Im storing prices in pennies e.g 399 but i want it to be displayed e.g £3.99p
how to do ? i used integers?

This would do it

int total = 399;
System.out.printf("\u00a3%1$d.%2$dp%n", total/100, total%100);

Wouldn't this do it for you?

int pound = price / 100;
int pennies = price % 100;
System.out.println("Price "+pound + "." + pennies);
//OR
System.out.println("Price "+ price/100 + "." + price%100);

Else you can play with formatting...

Yeah, that is the same thing. The formatting is just inlined with the printf().

Ah thanks. I was just a bit confused about what to do. Makes sense now (originally i was using floats and it didnt work how i wanted)

Haha I just realized what was going on. At first I read this and I was thinking "how is ezzeral's code going to produce that pound symbol?" because I literally thought you wanted that sign before the amount

"\u00a3" is the British pound symbol in unicode, so that output actually is what he stated he wanted: £3.99p

Most likely his own locale settings would place the local currency symbol in many formats though without having to put in the unicode for that particular symbol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.