print to only two decimal places.

Hello,

Problem:

When I do a division with the resultant value in float, I get values more than 3-4 decimal places. I would have to print this on the console.

What should I do in order to print it to just 2 decimal places.

Code:

Debug.Log("Distance travelled" + distance + "  m");

The NEED :

Considering the above code, the value distance prints itself to 4 decimals places. i.e.
I would like to have it printed as 4.56 rather than 4.56234.

THANK YOU VERY MUCH IN ADVANCE

You can use this:

Debug.Log("Distance travelled" + distance.ToString("F2") + "  m");

“Fn” format the float value to n decimal places.

Any of these solutions should work nicely for you: http://stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-pa