Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can i set the decimal value up to 3 decimal place.
Posted

For calculation purpose:
-> Whatever number you have, multiply it by 1000
-> then use Truncate
-> then divide by 1000.
Refer: MSDN: Math.Truncate Method (Double)[^]


If just for display purpose, you can try:
C#
double sample = 12.34567;
Console.Out.WriteLine(sample.ToString("#.000"));
 
Share this answer
 
v2
Comments
Kenneth Haugland 28-Jul-12 17:11pm    
I didnt know that... You = 5 :)
Sandeep Mewara 29-Jul-12 3:07am    
Thanks.
The function Truncate seems to be simular to

Math.Floor(Number)

except truncets works for negative numbers as well:
http://stackoverflow.com/questions/14/difference-between-math-floor-and-math-truncate-in-net[^]

As for display purposes there are quite a number of different formats:
http://msdn.microsoft.com/en-us/library/kfsatb94.aspx[^]

So there is just left for you to pick one:)
 
Share this answer
 
v2
Comments
Sandeep Mewara 29-Jul-12 15:28pm    
My 5 for additional option info!
Kenneth Haugland 29-Jul-12 15:36pm    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900