Quantcast
Channel: Excellent Web World » JQuery
Viewing all articles
Browse latest Browse all 10

Round value to 2 decimal points using PHP and Jquery

$
0
0

Sometime you get value 24.123456 in form. But you want only 24.12. What will you do for that?

USING PHP :

round(123.444,2);
Result : 123.44

USING jQuery :

var _round = Math.round;
Math.round = function(number, decimals /* optional, default 0 */)
{
if (arguments.length == 1)
return _round(number);

multiplier = Math.pow(10, decimals);
return _round(number * multiplier) / multiplier;
}

// examples
var fp = Math.round(123.4556, 2);
Result : 123.46

 

 

The post Round value to 2 decimal points using PHP and Jquery appeared first on Excellent Web World.


Viewing all articles
Browse latest Browse all 10

Trending Articles