Convert currency to decimal in PHP and JavaScript
I'm looking for the shortest/easiest way to achieve th开发者_开发技巧is.
var savings = <?php echo $list_price ?> - discount_price;
savings: 1.00
$list_price: '$10.00';
discount_price: '$9.00';
Cheers.
var savings = parseFloat('<?php echo $list_price ?>'.substr(1)) -
parseFloat(discount_price.substr(1));
This parses the string as a number, skipping the first characters (dollar).
isnt currency by default represented as a "decimal" (of sorts)
$1.00 = 1.00
0.50c = 0.5
Maybe this is the answer?
var savings = parseFloat(<?php echo $list_price ?>) - discount_price;
精彩评论