[SOLVED] Float values rounded to the first decimal position

Hi Guys,

I’m having a little issue while making calculations of the distance between the paddle and the ball. Apparently, the result is shown in the console as a float, but only of one decimal, so the result is rounded to the closest first decimal position (i.e 0.67 would appear as 0.7, and 0.62 would be 0.6). Besides, if I put something dumb like “print (0.7777775f);” then the whole number with all the decimal positions is shown in the console. On the other hand, if I write something like print(Input.mousePosition) then I get something like i.e. (139.0,120.0,0.0), which means, no decimal values are shown, though the value are shown in float format (the .0 indicates it). Finally using print(Input.mousePosition/Screen.width), then I get perfect float numbers with lot of decimal number between 0 and 1. I really have no idea what the hell is going on in there, so if anyone has any idea what could cause such a behaviour, please let me know.

Thanks in advance :wink:

This simply has to do with how the Unity editor prints out vectors. The float values it uses internally are still the correct ones.
As to why print(Input.mousePosition) prints decimals ending in .0, it’s because Input.mousePosition returns values in pixel coordinates (and there are no half-pixels).
Hope that helped :wink:

Thanks Sebastian,

I solved it with the “ToString(“F4”)” method, and now up to 4 decimal positions are shown. However, in the course the console is showing the whole decimal positions always, so I figured maybe is there somethimg in the unity settings that has to be changed of something like that. Any ideas Guys? thanks in advance :slight_smile:

That line is showing the last thing printed in the console, its nota a configuration

Then why in the course are being shown more decimal positions than the first, and I only get the first one rounded? i.e instead a of a difference between ball and paddle of 0.37, the console prints 0.4. I don’t know why I get a roundded value, while ben in the course gets an output in the console of the posittion with 2 digints accuracy, thanks guys ^^

Thanks for your answers guys, Its clear, on the vector is rounded, but by accessing the positions its shown with the necessary digits, I close the post.

Privacy & Terms