# Thread: Limit length of number irrespect of decimal places

1. ## Limit length of number irrespect of decimal places

I need to return a max of 8 digits to any number (not inc decimal point if necessary), but also want a max of 4 decimal places if the calculation provides a results with more than 4 dec places. This is because i have a max space of 8 characters + dec place.

eg

10.0908 (fewer than 8 digits so full 4 decimal places)
1908978.5 (max digits so could only return 1 dec place)
222.0192 (fewer than 8 digits so full 4 dec places shown)
1.19 (this is full answer so no changes required as !=> 8 digits & dec places<4 any way)

Hope this makes sense!!

2. What is the result?

123456.7555

3. For that matter, what would the result of 1234567890 be? Do non-fractional numbers keep their whole value?

4. Actually seems ok to squeeze any 9 characters in, so partly solved by this:

\$charLimit = 9;
if (strlen(\$answer) <= \$charLimit)
{
} else {
}

But this leaves me with sometimes having a decimal place as last character. Whats the best way to determine if the 9th character is the decimal point and if so remove it?

5. rtrim()

6. thanks!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•