Thanks:  0
Likes:  0
Dislikes:  0

# Thread: How to round of decimal places into 2 decimal places

1. ## How to round of decimal places into 2 decimal places

Hi ,I'm wondering if there is any function in silk to round of the decimal places to only 2 digts, or if someone can provide me the method how to do it
e.g number GotNumber = 2.65656899
I want to round off this number to only 2 decimal places like 2.66

2. ## Re: How to round of decimal places into 2 decimal places

GotNumber += .005 ; // round off
GotNumber *= 100 ; // move left of decimal point

GotNumber = [int]GotNumber ; // cast to an int to strip the fraction

GotNumber /= 100 ;
Print(GotNumber) ;

3. ## Re: How to round of decimal places into 2 decimal places

Another method:

iDec = 2
GotNumber = 2.65656899

sNum = Str (GotNumber, NULL, iDec)

print (sNum) // result: 2.66

This does the rounding for you, and you can set the number of decimal places. For more information, look up "Str" in the online help.

------------------
David Genrich
Icarian
555 North Mathilda Ave
Sunnyvale, CA 94086
davidg@icarian.com

4. ## Re: How to round of decimal places into 2 decimal places

Thanks it was of great help, it worked

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.