仅检索整数

时间:2017-04-12 06:08:19

标签: parseint escript

我想检索1.027863的整数部分,所以代码/函数应该给我1作为答案。

我的要求是通过将字符串拆分为153个字符的块来提供字符串中存在的SMS数量。

因此,如果有307个字符307/153 = 2.0065,我会使用ParseInt()函数取2并将其加1,表示SMS有3个部分。

但假设有306个字符是153的倍数,我的代码在答案中加1表示错误。

我做过的样本:

var String = "Hello test SMS for length and split it into sections of 153 characters for Bulk SMS system to send to respective customers and indicate the count of messages. SMS file is getting generated as per attached file. After successful campaign Launch, file can be downloaded from Documents view in Campaign screen.";
var i = 0;
var pat= new RegExp("^[a-zA-Z0-9]+$");
var flg = pat.test(String); 
if (flg == true) //checking the language to be English
{ 
var length = String.length;
if(length > 160)
{
    var msgcount = length / 153;
    var sAbs = parseInt(msgcount);
    var sTot = sAbs + 1;
    TheApplication().RaiseErrorText("Character " + length +" / 670   ( " + sTot +" msg)" );
}
} 

使用RaiseErrorText以格式显示:

Characters 307 / 1530 (3 msg)

也许有更好的方式来写这个。有什么建议专家吗?

1 个答案:

答案 0 :(得分:0)

而不是你的:

var msgcount = length / 153;
var sAbs = parseInt(msgcount);
var sTot = sAbs + 1;

你可以去:

var sTot = Math.ceil(length / 153);