How to convert to double with 2 precision - string after dot?

后端 未结 3 1186
逝去的感伤
逝去的感伤 2020-12-09 08:35

I want to convert this string: 0.55000000000000004 to this double: 0.55. How to do that?

3条回答
  •  既然无缘
    2020-12-09 09:04

    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 of double.

    Read The Floating-Point Guide to understand why.

提交回复
热议问题