turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Round up function to nearest decimal

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-14-2017 02:24 PM - edited 08-14-2017 02:28 PM

I'm trying to perform a roundup function to mimic the function in Excel where I want to round up to the nearest decimal.

For example I would like to round -0.2011 to -.202

I've tried round, ceil, and floor but I can't seem to get it to round at the decimal level, only the integer level.

Any help would be greatly appreciated.

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abcda

08-14-2017 02:40 PM - edited 08-14-2017 02:48 PM

newvalue=round(value+0.0005,0.001);

or

newvalue=ceil(1000*value)/1000;

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abcda

08-14-2017 02:49 PM - edited 08-14-2017 03:46 PM

If you are familiar with CEIL and FLOOR, you can probably do this yourself.

First, multiply by 1000. Then apply CEIL or FLOOR (might depend on whether the number is positive or negative). Then divide by 1000.

Be careful when you say rounding up or rounding down. To the mathematician, -0.2011 to -0.202 is rounding down.