I got:
int number = 1255; -> //It could also be 125(1€25Cent) or 10(10Cent) or 5(5Cent)
public double toMoney(int number)
{
...
}
as return, I want the double number: 12.55 or if input: 10 then: 00.10
I know that I can do with Modulo something like this:
1255 % 100.. to get 55.. But how to do it for 12 and at the end, how to
form it as a double?
If I’m understanding your question correctly, you’re probably trying to just do this:
Though a word of warning: You shouldn’t be using floating-point for money due to round-off issues.
If you just want to print the number in money format, here’s a 100% safe method:
This can probably be simplified a lot better… Of course you can go with BigDecimal, but IMO that’s smashing an ant with a sledgehammer.