Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
Joe Hayes

# Decimal Multiplier Problem

This might be simple but I don't know why it doesnt work.

```Decimal pricePerPerson = 100.00;
Decimal sellPerPerson = 1.1764705882352 * pricePerPerson;
sellPerPerson = sellPerPerson.setScale(2);```
This returns 117.65 as expectd.

However this...
```Integer discountPercent = 15;
Decimal pricePerPerson = 100.00;
Decimal sellPerPerson = (100/(100-discountPercent)) * pricePerPerson;
sellPerPerson = sellPerPerson.setScale(2);```
returns 100.00 and I'm not sure why. It should also return 117.65

Best Answer chosen by Joe Hayes
Sai Praveen (Salesforce Developers)
Hi joe,

As discountPercent is declared as Integer so (100/(100-discountPercent)) is returning Integer Value which is 1 and it is multipled with 100.00 gives you 100.00.

Instead of that define discountPercent as decimal then you will get required result.

Let me know if you face any issues.

Thanks,

mukesh gupta
Hi Joe,

```Decimal discountPercent = 15.00;
Decimal pricePerPerson = 100.00;
Decimal sellPerPerson = 100/(pricePerPerson-discountPercent) * pricePerPerson;
sellPerPerson = sellPerPerson.setScale(2);

system.debug('sellPerPerson== '+sellPerPerson);```

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

mukesh gupta
Hi Joe,

Or you can use below:-  both of code is tested my side

```Decimal discountPercent = 15.00;
Decimal pricePerPerson = 100.00;
Decimal sellPerPerson = 100/(100-discountPercent) * pricePerPerson;
sellPerPerson = sellPerPerson.setScale(2);

system.debug('sellPerPerson== '+sellPerPerson);```

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Sai Praveen (Salesforce Developers)
Hi joe,

As discountPercent is declared as Integer so (100/(100-discountPercent)) is returning Integer Value which is 1 and it is multipled with 100.00 gives you 100.00.

Instead of that define discountPercent as decimal then you will get required result.

Let me know if you face any issues.