javascript format price
问题 I wish to format a variable to a price format where if it is for example $90 then leave out the decimal which it already does anyway. But if the value is $44.5 then I want to format it as $44.50. I can do it in php not javascript. PHP example: number_format($price, !($price == (int)$price) * 2); The code I want to format: $(showdiv+' .calc_price span').html(sum_price); 回答1: var price = 44.5; var dplaces = price == parseInt(price, 10) ? 0 : 2; price = '$' + price.toFixed(dplaces); 回答2: PHPJS