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?

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...

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.

This article has been dead for over six months. Start a new discussion instead.