英文:
How to convert int32 to float javascript
问题
我需要将类型为int32
的值转换为浮点数值。
我有39900的值,我需要转换为399.00,或7400转换为74.00,或4378转换为43.78,它们不是固定值。
英文:
I need to convert values of type int32
to float values
I have the value of 39900 and I need to convert to 399.00, or 7400 to convert to 74.00 or 4378 to 43.78, they are not fixed values.
答案1
得分: 0
你只需要将数字除以 100
,这将把最后的2位数字放在小数部分。你不需要担心来自类C语言的整数和浮点数奇怪的情况,因为在JavaScript中,正如 @pilchard 指出的那样,所有数字都是浮点数。
英文:
You just need to divide the number by 100
, this will put the last 2 digits in the fractions. You don't need to worry about integer and float weirdness from C-like languages, since in Javascript, all numbers are floats, as @pilchard has pointed out.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论