4

I came across a weird issue. I have a percent field with precision up to 4 decimal points. We have some calculations which populate the value of that field. What I can see is after calculations if the value is low, its shown differently in classic and lightning. This popped up during a demo. I tested this on classic and gave a demo in lightning(which went bad). Ideally it should be same, if anyone can throw some light on this, would be helpful.

Value of **APR** in classic In Lightning In Developer Console

Steps to replicate:

  1. Create (14,4) precison % field

  2. Update it value to a lower number.

    Double d=Double.valueOf('6.2430516687936078306281214018618778468E-18');

    update new Opportunity(APR__C=d,id='00628000007Y078AAC');

  3. Try to view it in Lightning,Classic and Workbench. Each view will show different value.

  • That is an extraordinarily small number that I would expect to produce 0.0000% in both cases. What do you get when you query the value using e.g. the Developer Console? – Keith C Apr 11 '17 at 14:58
  • Updated pic to illustrate developer console value. – Pranay Jaiswal Apr 11 '17 at 15:13
  • 1
    I was able to replicate this for both numbers and percents in my dev org. Very strange indeed. I'd suggest creating a case and trying to get it logged as a known issue. – James Loghry Apr 11 '17 at 16:56
  • I have raised a case #16169993. Lets see what follow up we get. – Pranay Jaiswal Apr 11 '17 at 16:59
0

If you have chosen the database field to be 14,4 then to keep control of rounding you should use the Decimal type in your logic and invoke setScale(scale, roundsingMode) at the end of your Apex logic with a scale of 4 and your rounding mode of choice. That way what is presented and what is persisted in the database are the same; that avoids later surprises when hidden digit values influence later logic. Setting the scale of a field affects it presentation: it does not automatically scale the value when it is stored in the database.

(Having said that your results are surprising and indicate that extreme values - 6.2 Quintillionths in your case - are not well handled by default by the platform.)

  • Seems to be a bug in SF's rounding algorithm. It havent rounded properly while storing in the DB – Pranay Jaiswal Apr 11 '17 at 15:16
  • 2
    @PranayJaiswal Not a bug, more a design choice. – Keith C Apr 11 '17 at 15:49
0

Salesforce has identified it as a bug at their end and have provided a bug number W-3906558 . This is only reported by me so this cannot be marked as a known issue. For marking a bug as a known issue it should be brought to the notice by certain number of individuals. So No ETA as of now.

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.