Jump to content
We've recently updated our Privacy Statement, available here ×

error : divide by zero


siti141283

Recommended Posts

Hi,

I have a problem where i need to calculate percentage. I use this syntax to calculate the percentage, $V{A}/$V{B} * 100. The problem occur if $V{B} is 0. Anyone, please advise me how to solve this problem. can i do any kind of checking like if..else statement?

Thanks in advance... :unsure:

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi all..

 

Thanks to svenn.. :)

 

I've tried something similar to the code u gave me, that is : new Double(($V{B}.intValue() == 0) ? 0.00 : ($V{A}.intValue() / $V{B}.intValue() * 100))

 

$V{A} and $V{B} is integer type, so that i cast it to double. That code works perfectly for some of my textfields. But somehow i dont know why it didn't work for some other textfields, somehow it display 0.00 even both variables is not null. Does anyone have any idea why it didn't work?

 

to check if my code is correct or not, i try to use something like : new Double(($V{B}.intValue() == 0) ? 1.00 : 2.00), the value for $V{B} is 316, so when i run it, it display 2.00. So i know it can confirm that the code is correct. It's only when i put the calculation, it'll display 0.00 again.

 

I have similar textfields to display the percentage, but it is for variables with double data type. The code i use is : new Double(($V{C}.doubleValue() == 0.00) ? 0.00 : ($V{D}.doubleValue() / $V{C}.doubleValue() * 100)). That code works fine with all the textfields.

 

Can anyone help me to figure out why is this happening?

Link to comment
Share on other sites

Hi all,

Finally i'm able to solve the problem. Instead of using $V{A}.intValue() and $V{B}.intValue() for the calculation, i use $V{A}.doubleValue() and $V{B}.doubleValue(), and it works perfectly for all my textfields. ;)

Link to comment
Share on other sites

  • 2 weeks later...
  • 15 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...