开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜