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
Jeff TalbotJeff Talbot 

How can I apply a "1/3" discount?

I have a $25 product. If I create an Opportunity Line Item with a quantity of 12, my total price is $300. I want to discount the Total Price to $200 (a 1/3 discount).

 

If I enter a discount percentage of 33.33333%, it gets rounded or truncated to 33.33%, and my Total Price ends up at $200.01.

 

Any ideas how I can I get my Total Price to $200?

Best Answer chosen by Admin (Salesforce Developers) 
Jeff TalbotJeff Talbot

Resolution was to contact salesforce support and have them activate an option that makes 8 decimal places available on standard fields

All Answers

ryanjuptonryanjupton

I'm sure someone will have a better answer. But I got it working correctly with the following anonymous Apex.

 

Decimal price = 300.00;
Decimal discount = .333333;
Decimal calculatedDiscount = (price - (price * discount)).setScale(2);
System.assertEquals(200.00, calculatedDiscount);

 

 If that's what you're looking for it wouldn't be hard to implement that in an Apex class even though I played with it using anonymous Apex.

SachinSankadSachinSankad

Hi,

 

You can refer to math functions like ceil & floor in salesforce.

 

Here is link which consists of math functions in salesforce.

 

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

 

Thanks,

Sachin.

Jeff TalbotJeff Talbot

Thanks for the responses.

 

To clarify, "Total Price" is a standard Opportunity Product field that is formula based (Sales Price * Quantity), and I am unaware of any way to override this behavior. Sachin, are you suggesting that it is possible to override the standard behavior of the Total Price field with Apex code?

 

I also looked at the "Sales Price" field. This standard field only allows two decimal places. I don't see any way to change this, but if it could be changed to 6 decimal places, that would solve the problem.

 

Seems like such a simple problem. Lots of companies deal with fractions of pennies in their pricing all the time. Is Salesforce really not capable of handling this?

Jeff TalbotJeff Talbot

Resolution was to contact salesforce support and have them activate an option that makes 8 decimal places available on standard fields

This was selected as the best answer