0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javascript で前ゼロを表現する

Last updated at Posted at 2020-05-13

正数限定です。変数などで桁指定できます。
Number([数値]).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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?