Skip to content

Instantly share code, notes, and snippets.

@7cc
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save 7cc/1cb98bfc0fa0b3a39de4 to your computer and use it in GitHub Desktop.

Select an option

Save 7cc/1cb98bfc0fa0b3a39de4 to your computer and use it in GitHub Desktop.
  • fixed-point 固定小数点
  • Floating Point 浮動小数点
  • exponential notation 指数表記
method return
toFixed f
toPrecision f, e
toExponential e
var int = 12345.67
;["toFixed", "toPrecision", "toExponential"].map(function(e){
  return  e + "|" +  [1,2,3,4,5,6,7,8].map(function(e2){
    return int[e](e2)
  }).join("|")
}).join("\n")
method/arg 1 2 3 4 5 6 7 8
toFixed 12345.7 12345.67 12345.670 12345.6700 12345.67000 12345.670000 12345.6700000 12345.67000000
toPrecision 1e+4 1.2e+4 1.23e+4 1.235e+4 12346 12345.7 12345.67 12345.670
toExponential 1.2e+4 1.23e+4 1.235e+4 1.2346e+4 1.23457e+4 1.234567e+4 1.2345670e+4 1.23456700e+4
method/arg no-arg
toFixed 12346
toPrecision 12345.6789
toExponential 1.23456789e+4
toPrecision
引数が少 <------------> 多
  toExponential       toFixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment