I want to convert this string: 0.55000000000000004
to this double: 0.55
.
How to do that?
相关问题
- Generic Generics in Managed C++
- Do the Java Integer and Double objects have unnece
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
There is no double 0.55 - the number cannot be accurately represented as a binary fraction. Which is probably the reason why you got that long string in the first place. You should probably be using the
decimal
type instead ofdouble
.Read The Floating-Point Guide to understand why.
Is a string or a double? If it is a string:
if it is already a double just format using the second line.
you can use this code to reduce precision part:
Result would be : 0.55