Possible Duplicate:
c# – How do I round a decimal value to 2 decimal places (for output on a page)
how to return decimal with long rest after the point like that:
3.786444499963
to this:
3.787
its not just cut the points it also round the rest of the number
But the generally accepted rounding of
3.786444499963to three decimal places is3.786. Why do you think otherwise?Thus:
If you want it to ALWAYS round up:
Do you see what I did there? I added
0.0005mto the input before usingMath.Round. In general, to roundxtondecimal places,Or, perhaps, to avoid the ugly
double/decimalconversion:There’s an edge case you need to be aware of. What happens to 3.786? Should it be rounded up to 3.787 or remain at 3.786? You haven’t specified what you want exactly, so I’ll leave this edge case to you.