Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Number Format

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having two formatted numbers to be added Limit1 and Limit2
String Limit1=7,500.00;
String Limit2=7,000.00;
I have to add these two and get the result as 14,500.00

I followed the normal procedure with for loop and sustring.
my code is
String aloplimit1="";
for(int i=0;i<Limit1.length();i++)
{
if(!(Limit1.substring(i,i+1)).equals(",") && !(Limit1.substring(i,i+1)).equals("."))
aloplimit1+=Limit1.substring(i,i+1);
}
int aLimit=Integer.parseInt(aloplimit1);
same for Limit2
---
---
int bLimit=Integer.parseInt(aloplimit2);
int limit= aLimit+bLimit;
then formatted limit.

Please can any one tell me is there anyway to do this using numbers formatting with out writing lengthy code??

Thanks
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SCJP - Sun Certified Java Programmer forum.
This seems to be a general question, so it goes over to our Java In General forum.

Any SCJP'ers interested please look in the new location...
[ April 27, 2007: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhu,

Does this code satisfies your need,




I am looking forward to more specific solution!!!


Regards,
cmbhatt
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic