简体   繁体   中英

Convert currency to decimal in PHP and JavaScript

I'm looking for the shortest/easiest way to achieve this.

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

也许这就是答案?

var savings = parseFloat(<?php echo $list_price ?>) - discount_price;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM