我有一些JS:
var updateAmount = function (amount, rate) {
if (rate > 0 && amount.length > 0 && !isNaN(amount) && amount > 0) {
amount = Math.round(rate * amount * 100) / 100; // multiply rate with amount and then round to 2 decimals
$('.you-get').show();
$('#you-get').text(amount + ' ' + $currencyTo.find(':selected').text());
} else {
$('.you-get').hide();
}
};
Run Code Online (Sandbox Code Playgroud)
我需要的是一个子句,用于检查从中生成的值amount + $currencyTo.find是否为整数,如果再将其.00加到它的末尾。
if(amount === parseInt(amount)) //returns `true` if it's a integer
var updateAmount = function (amount, rate) {
if (rate > 0 && amount.length > 0 && !isNaN(amount) && amount > 0 && amount === parseInt(amount)) { //Edited this line
if(amount === parseInt(amount)) amount += '.00'; //Added this line
amount = Math.round(rate * amount * 100) / 100; // multiply rate with amount and then round to 2 decimals
$('.you-get').show();
$('#you-get').text(amount + ' ' + $currencyTo.find(':selected').text());
} else {
$('.you-get').hide();
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1152 次 |
| 最近记录: |