少于条件不适用于花车

sca*_*and 0 javascript jquery

继承我的jquery/javascript代码:

amount_sale = parseFloat($('#p_sale span').html()).toFixed(2);
amount_cash = parseFloat($('#p_cash span').html()).toFixed(2);

if (amount_cash < amount_sale)
{
    alert('Cash amount must be greater than or equal to sale amount');
    return;
}
Run Code Online (Sandbox Code Playgroud)

让我们说html如下:

<p id="p_sale">Sale: <span>10.00</span></p>
<p id="p_cash">Cash: <span>20.00</span></p>
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,即使p_cash范围内的内容大于p_sale范围内的内容,我仍然会收到警报.

我不懂.

Ry-*_*Ry- 5

toFixed将数字转换为固定字符串.在它之前,你只有一个数字,没有精确.我确定你想要:

amount_sale = parseFloat($('#p_sale span').html()).toFixed(2);
amount_cash = parseFloat($('#p_cash span').html()).toFixed(2);

if (amount_cash < amount_sale)
{
    alert('Cash amount must be greater than or equal to sale amount');
    return;
}
Run Code Online (Sandbox Code Playgroud)

通常情况下,这仍然适用于像10.0020.00- 但绝对不能128.503.14.