Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Converting pence into pounds help

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-16-2012, 07:47 PM PM User | #1 abell12 New Coder   Join Date: Mar 2012 Posts: 33 Thanks: 1 Thanked 1 Time in 1 Post Converting pence into pounds help I want to convert a pence value to pounds. So I have something like this: Code: ``` public double toPounds() { int itemPrice = 256; int pounds = itemPrice / 100; int pence = itemPrice % 100; return pounds + pence; }``` The int pounds works returning the value 2.0 for the 2 pounds. But its the pence im stuck on. Can anyone help me out. Thanks in advance.
 12-16-2012, 08:01 PM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,599 Thanks: 4 Thanked 2,598 Times in 2,567 Posts So pence is like 1 cent, and a pound is 100 cents? The problem here is that you should end up with 58. The reason is that 256 % 100 is 56, and 256 / 100 (as integer) is 2. So up to the return the values are still good to work with. You have pounds as 2 and pence as 56. Its the addition that you need to modify (as one of the several approaches), and you can simply `return pounds + (pence / 100.0);` as your return value. That should work as it will convert 56 to 0.56 which it then adds to the 2.0 (which is actually just 2, but that should be fine). Ultimately, if its just 100 pence per pound, then you can simply `return itemPrice / 100;`. You'll want to use a money formatter to constrain it to the 2 significant digits (with 100 as the divisor you could end up with only 1 significant digit, but I don't think you can end up with 3+ significant digits).
 Users who have thanked Fou-Lu for this post: abell12 (12-16-2012)
 12-16-2012, 08:07 PM PM User | #3 abell12 New Coder   Join Date: Mar 2012 Posts: 33 Thanks: 1 Thanked 1 Time in 1 Post Thanks so much it works. Yes pence is like 1 cent, and a pound is 100 cents, either way you got the idea.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 10:46 AM.