Jump to content
  • 0

Request arithmetic operators


Question

Posted

I'm creating a percentage config for VIP I want them to have 30% discount for teleport but what would be the option in java for integers? For example

 

 

final int price = 10000

 

getVip() ? price % 10  : price

 

result = 0

 

when debugging my value is 0 but it should be 1000

3 answers to this question

Recommended Posts

  • 0
Posted

You using % = mod (modulo), that means number 10.000 divined with 10, will have a result of 1.000

and 0 remaining.

Another example: 11 mod 4 = 3, because 11 divides by 4 (twice), with 3 remaining.

 

You can take the 30% percentage by the following:

int finalPrice = (int) (getVip() ? (price - price * 0.30) : price);

 

  • Thanks 1
  • 0
Posted
3 hours ago, @IcathiaLord said:

You using % = mod (modulo), that means number 10.000 divined with 10, will have a result of 1.000

and 0 remaining.

Another example: 11 mod 4 = 3, because 11 divides by 4 (twice), with 3 remaining.

 

You can take the 30% percentage by the following:

int finalPrice = (int) (getVip() ? (price - price * 0.30) : price);

 

thank you i get it

Guest
This topic is now closed to further replies.


×
×
  • Create New...