[英]Convert JavaScript string which is a decimal number to number without loosing trailing zeros
I am trying to convert a string that is a decimal number to a number without losing the zeros at the end 我正在尝试将十进制数字的字符串转换为数字,而不会在最后丢失零
Convert javaScript floating point numbers to string without loosing insignificant trailing zeros solution here returns a string, not a number 将javaScript浮点数转换为字符串而不丢失不重要的尾随零的解决方案这里返回字符串,而不是数字
let myNumber = '0.10'
parseFloat(myNumber) // 0.1
parseFloat(myNumber).toFixed(2) // "0.10"
Number(parseFloat(myNumber).toFixed(2)) // 0.1
Desired output - convertToNumber('0.10') -> 0.10
I think if you were to create a Number object the only value that it could be is .1. 我认为,如果要创建一个Number对象,则它可能唯一的值为.1。 This is done within the number class, so I do not think you can change this
这是在数字类中完成的,因此我认为您无法更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.