4 Replies Latest reply on Jan 25, 2008 1:35 PM by reinhat

# Need urgent help! How to check if the generated number is a whole number

Hi,
I have a simple issue but I need some assistance. I am calculating a number and the result number sometimes a whole number but in some cases decimals are present. Decimals do not need change but whole numbers need to change. So for example if the end result is "6" I need it to show it as "6.0" in a field beacuse that is the way the calculator should display it according to request.
How can I check that the result number is a whole number and then add ".0" to it?
I just included a simple script below.

if (outputnumber == ?) {
resultNum = Number(String(outputnumber+".0"));
} else {
resultNum = outputnumber;
}

Thanks,
Attila
• ###### 1. Need urgent help! How to check if the generated number is a whole number
try this

if (Math.floor(outputnumber)== outputnumber) {
resultString = outputnumber+".0";
} else {
resultString = String(outputnumber);
}
• ###### 2. Re: Need urgent help! How to check if the generated number is a whole number
The above mentioned example returns "NaN".
How can it return numeric value?
• ###### 3. Re: Need urgent help! How to check if the generated number is a whole number
Hi reinhat,

That means that "outputnumber" wasn't something that can be converted to
a number. When you trace this value, what do you see?

Regards,
Patrick Bay
BAY NEW MEDIA

"reinhat" <webforumsuser@macromedia.com> wrote in message
news:fndgeh\$484\$1@forums.macromedia.com...
> The above mentioned example returns "NaN".
> How can it return numeric value?

• ###### 4. Re: Need urgent help! How to check if the generated number is a whole number
I got it. I had to convert it from string to number. :)