Decimal divided-by Integer and Decimal divided-by Decimal for the exact same values return different results!

Example: (1) 84.5/100 = 0.85 Whereas (2) 84.5/100.0 = 0.845

To add to that, when we set BOTH the numbers to Decimal properties the result is (1).

Any clue why?

***Edited by Moderator: Marissa to update categories***

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.


Keep up to date on this post and subscribe to comments

June 20, 2017 - 2:28am

Hi Viswa,

If you give 85.0/100 we are considering them as bigdecimal values and thus returning the value round to two decimal points.

Whereas if we give 85.0/100.0, it is treating them as both normal decimals and hence no rounding.

You can play with the values and check view Java in activity to get some clarity on what's happening why.

Hope this helps.



July 4, 2017 - 12:05pm
Response to Raviteja_GCS

Hi Ravi,

Thanks for your reply.

There is no clarity on why this is happening but I figured a workaround.

Instead of doing 85.0/100.0, I am doing 85.0/100.0000000000000001.This solves my problem at hand.



July 4, 2017 - 10:40pm
Response to Viswa_CG

Hi Viswa,

Both those would give us the same result right?


July 8, 2017 - 2:30pm
Response to Raviteja_GCS

They somehow don't. Try out the exact example I put in the beginning of the thread and the workaround I mentioned. The results are interesting (they shouldn't be interesting!).

July 27, 2017 - 3:14pm
Response to Viswa_CG

Where are you adding this code ?  In an activity java step or somewhere else?