search

Home  >  Q&A  >  body text

javascript - js formatted data

For example:
10 is formatted as 10.00
1.1 is formatted as 1.10
2.21 is formatted as 2.21

No other circumstances

There is BigDecimal in java that can be used. Is there anything similar in js?

世界只因有你世界只因有你2748 days ago888

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 10:58:09

    .toFixed(2)

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 10:58:09

    printf module

    const printf = require('printf')
    printf('%.2f', 10) //10.00

    toFixed method

    (10).toFixed(2) //10.00

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-18 10:58:09

    Use toFixed (number of decimal places)

    var a=1;
    a.toFixed(2) //"1.00"
    typeof a // "number"

    reply
    0
  • Cancelreply