Trailing zeros in javascript

后端 未结 2 853
梦毁少年i
梦毁少年i 2021-01-25 13:06

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 zero

相关标签:
2条回答
  • 2021-01-25 14:00

    The number 47.0 is the same number as 47, so the only way to change its representation is to make it a string.

    0 讨论(0)
  • 2021-01-25 14:02

    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.

    0 讨论(0)
提交回复
热议问题