function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NatrajNatraj 

Rounding a number

Hi All,

 

I need to round numbers similar to the example below.

 

5.2 should be rounded to 5

 

5.3 to 5.7 should be rounded to 5.5

 

Greater than 5.7 to 6.

 

Is there any formula function or known way to do this?

 

Help me in this.

 

Thanks !!

imutsavimutsav
I don't think what you are trying would be exactly possible. But still the below link would help you get more information. It has all the methods available to round off.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm

Thanks
Utsav

[Do mark this answer as solution if it works for you and give a kudos.]
Shannon HaleShannon Hale

The only thing I can think of that would allow you to do this in a formula field would be something like this:

 

IF (
  Number__c - FLOOR( Number__c ) < 0.2,
  FLOOR( Number__c ),
  IF (
    Number__c - FLOOR( Number__c ) > 0.7,
    CEILING( Number__c ),
    FLOOR( Number__c ) + 0.5
  )
)

Subtracting FLOOR( Number__c ) from the number gives you the decimal value.

 

If the decimal value is less than 0.2, return FLOOR( Number__c ) -- rounding down.

If the decimal value is greater than 0.7, return CEILING( Number__c ) -- rounding up.

Otherwise, returning FLOOR( Number__c ) + 0.5 gives you N.5.