JavaScript Number.toPrecision

From SwiftAPI

Jump to: navigation, search

Template:API FUNCTION: javascript, Number, toPrecision

JavaScript

var p = 4;
var x = 3.14159;
var y = x.toPrecision(p);
// y == "3.142"

PHP

$p = 4;
$x = 3.14159;
$y = number_format($x, $p - 1);
// $y == "3.142"
Personal tools