In c# double type how can i set the number of digits after the point, i need only 4. thank you.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- Do the Java Integer and Double objects have unnece
- 求获取指定qq 资料的方法
You can't. Binary floating point doesn't work like that. You can format a double that way (e.g. using
"f4"
as the format string), but if you're dealing with values which have a natural number of decimal places, then you should probably be usingdecimal
instead. Could you give us more information about what your values represent?You can't set the number of digits after the point on the double directly.
You can change the string representation of the double using a format string.
One example would be:
Or as Jon Skeet points out:
Use this to compare two floating point numbers to 4 digits in the fraction: