Last active
August 29, 2015 14:27
-
-
Save shiranuik/bcde1718694e1f4caead to your computer and use it in GitHub Desktop.
javascriptで小数点以下0詰め
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// キモはNumber.toFixed() | |
// これは、Numberを()内で指定した固定小数点の数にしてくれる。 | |
// (0.6).toFixed(3) => 0.600 みたいな感じ。 | |
// formには0詰めされたフォーマットが入っている(0.000みたいな) | |
// (※何種類かフォーマットを使い分ける必要があったので… | |
var aaa = 0.6; | |
var tmp = form.split('\.'); //小数点前後で分割する。 | |
var num = tmp.length==1?0:tmp[1].length; //小数点以下の桁数を取得。小数点がなければ0。 | |
aaa.toFixed(num); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment