Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console.WriteLine(myFloat.ToString()) with two decimals? 2

Status
Not open for further replies.

d00ape

Programmer
Apr 2, 2003
171
SE
I want to print a float with value 1.98765 with only 2 decimals: (1.99 in this case).
How?
 
This will do it

Code:
float number = 1.98765f;
Console.WriteLine(Math.Round((decimal)number, 2).ToString());

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
... or

Code:
Console.WriteLine(number.ToString("0.00"));

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top