我有以下代码来检索结果。
var _label:Number = (data.ask - data.bid) * 10000;
this.text = String(_label.toFixed(0));
我想知道要添加什么才能仅检索结果的左侧前 2 个数字。例如:
1234756.21354 > 12
75484.014 > 75最佳答案
您可以使用.substr() , .slice()或.substring()方法:
this.text = String(_label.toFixed(0)).substr(0,2);
//this.text = String(_label.toFixed(0)).slice(0,2);
//this.text = String(_label.toFixed(0)).substring(0,2);
要在之间添加 .
(dot),请尝试以下操作:
var numstr:String = String(_label.toFixed(0)).substr(0,2);
this.text = Number(numstr)/10 + "";
关于javascript - Flex (toFixed) 数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629363/