1

i'm try to make a random or unique code to payment method, for example the user must pay for Rp. 10.000 and then the user checkout and the system give the total payment with unique code in last three number.

For example user should pay for Rp. 10.000 and then the system showing Rp. 10.123 for other example, user pay for 1.000.000 and then system showing the total is 1.000.562 just unique or random in last three number

how i can make like this in java for android ?

UPDATE

i've been try this code

int someNumber = 10.000;
int lastThree = someNumber % 1000;

but when the last 3 number is '0' it return 0, when i'm change the last 3 number like 10.234 it return into 234, now how i can get the last three number when the value is like 10.000

4

1 Answer 1

1

That's because your 'lastThree' is an integer and there is no way to have an integer like 000. if you need last three number, you can use something like this:

int someNumber = 10.000;
String temp = Integer.toString(someNumber);
String lastThree = temp.substring(temp.length() - 3);

Now if you pass 10000, lastThree will be '000'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.