Problem converting from int to float

前端 未结 6 1863
[愿得一人]
[愿得一人] 2021-01-02 00:27

There is a strange behavior I cannot understand. Agreed that float point number are approximations, so even operations that are obviously returning a number without decimal

6条回答
  •  一整个雨季
    2021-01-02 00:42

    When you multiply by 100, that is an integer, so it is doing an implicit conversion at that step. If you put an "F" behind the 100, I'll bet they'd be the same.

    I typically use boxing/unboxing with the parentheses when it is a reference type. When it is a value type, I try to use the Convert static methods.

    Try Convert.ToSingle(YourNumber); for a more reliable conversion.

    HTH

提交回复
热议问题