0

If I get a String value like

$10

what is the best and concise way of to verify the currency value?

Currently I am using Usual String Methods like startsWith("$") and get the rest and change them to Double value if they are numeric.

Dilshad Abduwali
  • 1,388
  • 7
  • 26
  • 47
  • 4
    What do you mean by "verify the currency value"? – Tunaki Oct 13 '15 at 13:03
  • do you have pre-defined format? how about RegEx? – hamid Oct 13 '15 at 13:04
  • basically I need to check if the string is a currency or not if yes I need to extract the numeric value for other purposes. – Dilshad Abduwali Oct 13 '15 at 13:04
  • 1
    Possible duplicate of [Java Regular Expression to match dollar amounts](http://stackoverflow.com/questions/17864213/java-regular-expression-to-match-dollar-amounts) – Abubakkar Oct 13 '15 at 13:05
  • it must start with $ – Dilshad Abduwali Oct 13 '15 at 13:07
  • 4
    By the way, [you shouldn't use floating point data types for currency](http://stackoverflow.com/q/3730019/4125191). – RealSkeptic Oct 13 '15 at 13:08
  • And how do you know whether $ is US or Canada? There is a [`Currency`](http://docs.oracle.com/javase/8/docs/api/java/util/Currency.html) class in java (and/or preferably [Joda-Money](http://www.joda.org/joda-money/)). But apart from those, you'll need to do the splitting part manually based on your requirements. – Petr Janeček Oct 13 '15 at 13:14
  • see http://stackoverflow.com/questions/2544454/get-the-currency-format-for-a-country-that-does-not-have-a-locale-constant – vikingsteve Oct 13 '15 at 13:22

0 Answers0