弹性(到固定)数字格式

Flex (toFixed) numbers formatting

本文关键字:数字 格式 弹性      更新时间:2024-02-20

我有以下代码来检索结果。

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);

要在两者之间添加.(点),请尝试以下操作:

var numstr:String = String(_label.toFixed(0)).substr(0,2);
this.text = Number(numstr)/10 + "";