简体   繁体   English

在JavaScript中小数点后加0

[英]Adding 0s after the decimal point in javascript

I have searched through a lot of threads and all of them give the same answer. 我搜索了很多线程,并且所有线程都给出了相同的答案。

I am trying to add 0s right after the decimal point to an integer. 我试图在小数点后立即将0加到整数。 If I have var a = 25. I want to modify a such that its value is 25.0. 如果我的var a =25。我想修改a使其值为25.0。 Most of the offered solutions either suggest appending a string ".0" or using .toFixed() which appends any number of 0s you want but still returns a string. 提供的大多数解决方案都建议附加一个字符串“ .0”或使用.toFixed()附加所需的任意数量的0,但仍返回一个字符串。 I want the response to be float number and not a string. 我希望响应是浮点数而不是字符串。

Any thoughts on how I could achieve this? 关于如何实现此目标有任何想法吗?

Thanks. 谢谢。

It has been a while since someone used this thread, but just in case someone needs it I think the answer you are looking for is: 自从有人使用此线程已经有一段时间了,但万一有人需要它,我想您正在寻找的答案是:

.toFixed(2)

Example: 例:

let number = 4;
return number.toFixed(2) //4.00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM