0
Decimal a = 60000.000;
Decimal b = 2000.0000;
system.debug(a/b);

Expected Output: 30

Actual: enter image description here

Is there anything did I miss? Why this weird behavior?

1
  • 1
    But is not 3E+1 same as 3*10^1 => 30?
    – kurunve
    May 6, 2020 at 7:17

1 Answer 1

1

As mentioned in the question comments by kurunve 30E+1 is same as 30 but still if you want to see 30 in the debug logs you can either round the output to nearest integer by using Math.round(decimalValueHere) or if decimal points are required then you may use set scale as below:

Decimal a = 60000.000;
Decimal b = 2000.0000;
system.debug((a/b).setScale(4));

//output: 30.0000 as we have set scale to 4 
2
  • Do you know the exact reason why 30 is represented as 3E+1 only in some cases?
    – Pardhu
    May 6, 2020 at 9:16
  • I would say since you are computing higher numbers, so just to consume less space it uses 3E+1 but it just debug logs doesn't matter if it shows 30 or 3E+1, your other calculations won't get impacted because of this, or if you want to display it on any custom page it won't come as 3E+1, may I know the exact reason you want 30 instead of 3E+1?
    – gs650x
    May 6, 2020 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .