简体   繁体   中英

Trailing zeros in javascript

Is there a way to add trailing zeros to a number in javascript?

For example: 47.0 instead of 47 or 0.0 instead of 0

when I return the numbers in a json, the zeros disapper.

I need them to be numbers and not strings so .toFixed(2) doesn't help.

Thanks!

数字47.0与47是相同的数字,因此更改其表示形式的唯一方法是使其成为字符串。

No. What you want is a specific presentation, which most simple types has no concept of.

Anyway, when serialized into a JSON request or response it would still be converted to a string, but the receiving end shouldn't care at all if it's represented as 46.0, 46.00 or 46.000 unless it has the "" around it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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