• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formating this: #,#####.### to this: #####.####  RSS feed

 
Carlos Gavidia
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I obtain a paramater from the request: is a String that represents certain number, but with a comma as a thousand - separator (i.e : 1,456.12), is there a class that can convert this string into a database-friendly format? (ie 1456.12): or the only solution is to remove the comma??
 
Zaheer A Baloch
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure whether the api provides any method for this conversion but you can use the following method to remove the comma easily.

public static double convertNum(String strNumber) {

return (Double.parseDouble(strNumber.replaceAll(",", "")));

}

Calling the method:
double dblValue = convertNum("1,456.12");

Hope this helps...

// Zaheer
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the DecimalFormat class to parse your input String into a number.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!