如何将int32转换为浮点数JavaScript

huangapple go评论66阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月7日 01:25:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定