LoginSignup
0
0

More than 3 years have passed since last update.

Javascript で前ゼロを表現する

Posted at

正数限定です。変数などで桁指定できます。
Numer([数値]).toPrecision([桁数]).split('.').sort().join('')

・Number([数値]) で toPrecision を使えるようにします。
・toPrecision([桁数]) で、たとえば "123.00" のような表現になります。ここで文字列になります。
・次の split('.') で ["123", "00"] になります。ここで配列型になります。
・sort() で["00", "123"]になります。
・最後の join で連結します。"00123"

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0