javascript - limiting to 2 places, tofixed not working -
.tofixed(2).
i have working fine, accurate answers.
        var la_95_m = document.getelementbyid("la_95_charge_m"); la_95_m.value = (((total_current_storage.value / total_current_draw_30.value) / cd5_factor) * bc_95_sd_ad) * new_old_factor; i need wrap "var la_95_m" tofixed(2) no matter how have tried keep breaking script.
all of these
var la_95_m.tofixed(2);  var la_95_m.value.tofixed(2);  var la_95_m.tofixed(2) = document.getelementbyid("la_95_charge_m");                     la_95_m.value = (((total_current_storage.value / total_current_draw_30.value) / cd5_factor) * bc_95_sd_ad) * new_old_factor; break it.
any tips/help appreciated
you can't declare variables have type .tofixed(), variations on:
var la_95_m.tofixed(2) will not work.
you need call .tofixed(2) on result of calculation:
var result = (((total_current_storage.value / total_current_draw_30.value) / cd5_factor) * bc_95_sd_ad) * new_old_factor; la_95_m.value = result.tofixed(2); where result contains numeric value, result.tofixed(2) returns string number 2 decimal places. (if result not numeric you'll error.)
to without creating result variable, wrap calculation in parentheses , call .tofixed(2) on that:
la_95_m.value = (someexpressionthatisnumeric).tofixed(2);  la_95_m.value = ((((total_current_storage.value / total_current_draw_30.value) / cd5_factor)                  * bc_95_sd_ad) * new_old_factor).tofixed(2); 
Comments
Post a Comment