简体   繁体   中英

numbers and text in same field

I can't get the numbers and text in same form field to force two decimal places or do Total figure.

This is the link .

I am trying to get the last 3 cells to work with two decimal places. eg Total sq mt figure x Price should calculate the Cost cell.

Also want to get the Cost cell (NaN) working ! Thanks.

In general, you want to do something like this

function calc(val1, val2) { // this is NOT a replacement for your Calculate function
    val1 = parseFloat(val1.replace(/[^\d\.-]/g, ''));
    val2 = parseFloat(val2.replace(/[^\d\.-]/g, ''));
    return (val1 * val2).toFixed(2);
}

NOTE: the above returns a STRING

and STOP redefining with Math.round in your code

var result = Math.round(num * 100.0) / 100.0;

应该用两位小数位格式化您的数字。

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