I want to retrieve the whole number part of 1.027863, so the code/function should give me 1 as the answer.
My requirement is to provide the number of SMSs present in a string by splitting the same into blocks of 153 characters.
So if there are 307 character 307/153 = 2.0065, I would take 2 using the ParseInt() function and add 1 to the same indicating that there are 3 parts to the SMS.
However assuming there are 306 characters which is a multiple of 153, my code is adding 1 to the answer making it wrong.
Sample of what I have done :
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)" );
}
}
Where RaiseErrorText is used to Display in the format:
Characters 307 / 1530 (3 msg)
Maybe there is a better way to write this. Any suggestions experts?