Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Double To Two Decimal Places [duplicate]

Tags:

c#

c#-4.0

Possible Duplicate:
c# - How do I round a decimal value to 2 decimal places (for output on a page)

What is the best way to round a double to two decimal places and also have it fixed at 2 decimal places?

Example: 2.346 -> 2.35, 2 -> 2.00

I am hoping to avoid something like this where I have to convert a double to string and then back to a double which seems like a bad way to go about this.

like image 783
Robert Avatar asked Sep 03 '25 14:09

Robert


1 Answers

double someValue = 2.346;    
String.Format("{0:0.00}", someValue);
like image 86
Mike Avatar answered Sep 05 '25 15:09

Mike