如何将Int数转换为双数? [英] How to Convert Int number to Double number?

查看:153
本文介绍了如何将Int数转换为双数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Javascript:



如何将一个数字整数转换为双数字示例:

  100  - > 100.00 


解决方案

JavaScript 中的所有数字都是 doubles:也就是说,它们被存储为64位IEEE-754双打。



那就是,目标是不要得到一个double:目标是获取格式为YYY.XX的数字的字符串reprsentation。为此,请考虑 Number.toFixed ,例如:

 (100).toFixed(2)
/ pre>

结果是字符串(不是double!)100.00。在这种情况下,括号需要避免语法模糊(也可以写为 100.0.toFixed 100..to固定),但如果100是变量,则不需要。



快乐编码。


Using Javascript:

How I can convert one number integer to Double Number Example:

100 -> 100.00

解决方案

All numbers in JavaScript are doubles: that is, they are stored as 64-bit IEEE-754 doubles.

That is, the goal is not to get a "double": the goal is to get the string reprsentation of a number formatted as "YYY.XX". For that, consider Number.toFixed, for instance:

(100).toFixed(2)

The result is the string (not a "double"!) "100.00". The parenthesis are required to avoid a grammar ambiguity in this case (it could also have been written as 100.0.toFixed or 100..toFixed), but would not be required if 100 was in a variable.

Happy coding.

这篇关于如何将Int数转换为双数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆