.toFixed(2)。
我的工作正常,我得到了准确的答案。
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;
我需要包装" var la_95_m"使用toFixed(2)但无论我怎么试过它,我都会打破脚本。
所有这些
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;
打破它。
感谢任何提示/帮助
答案 0 :(得分:3)
您无法声明变量的类型为.toFixed()
,因此请参阅:
var la_95_m.toFixed(2)
将不工作。
您需要在计算结果上调用.toFixed(2)
:
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);
result
包含数值,result.toFixed(2)
返回一个字符串,该字符串是带有两个小数位的数字。 (如果result
不数字,则会收到错误。)
要在不创建额外result
变量的情况下执行此操作,请将计算括在括号中并在其上调用.toFixed(2)
:
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);
答案 1 :(得分:0)
将// first load your new data to your picker view's data source (not shown here...) then load the data into the picker view using it's delegate
[self.fieldPicker reloadAllComponents];
// now that the data is loaded, select a row in the picker view through it's delegate
[self.fieldPicker selectRow:([self.theFields count] - 1) inComponent:0 animated:NO];
// retrieve the row selected in the picker view to use in setting data from your data source in textboxes etc.
long row = (long)[self.fieldPicker selectedRowInComponent: 0];
更改为var la_95_m.toFixed(2);
。
la_95_m.value = la_95_m.value.toFixed(2);
实际上并没有更改您调用它的号码的值,它只返回一个包含n位的新字符串。