[Solved] 'float' format inconsistencies

NLast project when we pass floats we are recommended to pass them like “-5.0f”, yet this project float xmin = -5 stares at me coldly. Is it not a big deal to pass the value 5.0 without the ‘f’ suffix?

2 Likes

I would suggest always adding the suffix for floats to avoid any issues going forwards.

In the documentation I link to below, you’ll note the comment regarding how a compilation error will be caused if the suffix (in that example) is missing. I suspect the reason this doesn’t occur in the above is because you are specifying a whole number -5.


See also;

  • MSDN C# Reference : Float
1 Like

That’s correct. It’s one of those things where the compiler is smarter than it should be, as it leads to sloppy habits. Agreed, if it’s a float, it gets an f.

2 Likes