2

I've been migrating some QuoteLineItem and OpportunityLineItem records, and I noticed an odd behavior of the Salesforce platform.

First, here are the field definitions:

QuoteLineItem standard fields

Here, we can see that:

  • Discount has a length of 3, with 2 decimals
  • UnitPrice has a length of 16, with 2 decimals
  • TotalPrice has a length of 16, with 2 decimals

Now, if I try to update an existing QuoteLineItem record using the developer console and add a ton of decimals to Discount and UnitPrice:

insert new QuoteLineItem(Id ='some-existing-id', Discount=27.777777777777777777, UnitPrice=1800.77777777777777777777, Quantity=1);

System.debug([SELECT UnitPrice, Discount, Quantity, TotalPrice FROM QuoteLineItem WHERE Id = 'some-existing-id']);

The debug log displays that:

16:03:22:696 USER_DEBUG [5]|DEBUG|QuoteLineItem:{Quantity=1.00, TotalPrice=1300.56172841, Discount=27.777777777777777777, Id=some-existing-id, UnitPrice=1800.77777778}

Straight there, I already see that Discount number of decimal is 18 instead of 2, TotalPrice and UnitPrice have 8 instead of 2.


Now, if I go in the Salesforce UI, this is what I see:

QuoteLineItem UI

We only see 2 decimals for each field, instead of 18. But, again, the surprising thing is that if you edit any field, this is what you get:

QuoteLineItem Edit Mode

They all end up with 3 decimals, instead of the 2 in the object definition or the 18/8 in the developer console. Let's say I have a UnitPrice or Discount with multiple decimals, I could end up with a scenario where a end-user using the UI couldn't get the right result if he tries to multiply the Quantity, UnitPrice and Discount together.


Finally, if I decide to update the discount with more than 3 decimals & save:

enter image description here

This is what we have: the platform chopped to 2 decimals:

enter image description here


Is there a reason for this odd behavior? Rules when inserting/updating records in Apex or using the DataLoader should obey to the same rules as if they are inserted using the UI. Now, it feels like there's a soft validation rule using the UI, and a strong one when we update data programatically.

5

This is not an odd behavior.If your company sell items at a very small price,Contact salesforce.com support and ask them to enable the permission:"More decimals on price".

Turning the feature on will open up all price fields in Salesforce so they can be edited for up to 8 decimals to the right of the decimal point. The display will always show at least the currency-length number of digits and up to 8 depending on how many digits are needed by that value. For example, in USD, the values below will display in the following manner: $0.00045 will display as $0.00045 $0.12345678 will display as $0.12345678 $10 will display as $10.00 $10.02 will display as $10.02 $10.12345 will display as $10.12345

(2) Price formats will no longer be enforced/defaulted and could therefore vary - Within an organization - For example, if you sell some products/services at prices like $1,500.00 and others at $0.00045 - For the same product between various list and sales prices - For example, if list price for a product was $0.00045, nothing would stop a user from applying a sales price for the product of $1.45 or $145.00 or $0.00000045 on an opportunity line item

(3) In reports, price fields will be right aligned and may not line up vertically at the decimal point if formats vary.

(4) The feature can be turned off again for your org on request. In that case, prices will be rounded back down to the currency-length number of digits. For example, if you had a price defined for a product of $0.12345, it would be rounded back to $0.12 if the feature was disabled.

Let me know if it helps.

| improve this answer | |
  • 1
    woah, that is great to know you can ask salesforce to increase the precision on price, I've done so many customizations to deal with that ... – Ralph Callaway Jun 30 '14 at 22:00
  • Good to know. A few month ago the support told us this would not be possible, but now I will make a follow up. – Uwe Heim Jul 1 '14 at 0:06
0

The behavior you describe is not any different that my experience with other numeric fields. The UI is in fact doing all of the enforcement of the number of decimals. When you insert something using API or Apex, you can put as many decimals as you want.

You must enforce decimal places yourself in all code and API calls.

| improve this answer | |
0

Salesforce internally stores all values to the greatest possible precision. This can cause odd rounding effects, such as a line item with a cost of $9.991, and a quantity of 10, resulting in a total value of $99.91 (but the UI would show unit price $9.99).

You should always be aware of this if you're writing code that might adjust the unit price to include more decimal places than the UI is configured to show. This is true for all standard and custom number fields.

As stated in the other answers,you can intentionally increase the visible decimal places if you have a need for it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.