Skip to main content
edited title
Link
cropredy
  • 73.3k
  • 8
  • 128
  • 284

Apex division losing precissionprecision

Post Reopened by Adrian Larson apex
Post Closed as "Duplicate" by Adrian Larson apex
deleted 8 characters in body
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

I am having some issues related to the precision with Decimals. Let's take a look at the following scenario:

Decimal total = (5 / 3) * 3;
System.debug(total) // this will print 4.9999999999999999

total = 5 * 3 / 3;
System.debug(total) // this will print 5

theThe reason seems that in the first operation, the number that arrives at the multiplication is 1.66666666666666666 (Decimal precision)

isIs there any know bug from salesforce with this?

because Because in other languages I don't observe this is not happening

Cheersbehavior.

I am having some issues related to the precision with Decimals. Let's take a look at the following scenario:

Decimal total = (5 / 3) * 3;
System.debug(total) // this will print 4.9999999999999999

total = 5 * 3 / 3;
System.debug(total) // this will print 5

the reason seems that in the first operation, the number that arrives at the multiplication is 1.66666666666666666 (Decimal precision)

is there any know bug from salesforce with this?

because in other languages this is not happening

Cheers

I am having some issues related to the precision with Decimals. Let's take a look at the following scenario:

Decimal total = (5 / 3) * 3;
System.debug(total) // this will print 4.9999999999999999

total = 5 * 3 / 3;
System.debug(total) // this will print 5

The reason seems that in the first operation, the number that arrives at the multiplication is 1.66666666666666666 (Decimal precision)

Is there any know bug from salesforce with this? Because in other languages I don't observe this behavior.

Source Link
junjs
  • 43
  • 1
  • 5

Apex division losing precission

I am having some issues related to the precision with Decimals. Let's take a look at the following scenario:

Decimal total = (5 / 3) * 3;
System.debug(total) // this will print 4.9999999999999999

total = 5 * 3 / 3;
System.debug(total) // this will print 5

the reason seems that in the first operation, the number that arrives at the multiplication is 1.66666666666666666 (Decimal precision)

is there any know bug from salesforce with this?

because in other languages this is not happening

Cheers