How to get a Persian number from a text field and convert to double in Java?

How to convert "12345" Persian line numbers to double?

I want to get a Persian number from a text box and store it in a double variable. I tried:

product.setSellPrice(Double.parseDouble(txtProductSalePrice.getText())); 

but this throws Caused by: java.lang.NumberFormatException: For input string:

+5
source share
2 answers

You can split the string into characters and scroll through the characters using, for example, toCharArray() , and then convert each number to its English.

 String number = ""; for (char c : txtProductSalePrice.toCharArray()) { if (c == "Ϋ±") { number.concat("1"); continue; } if (c == "Ϋ²") { number.concat("2"); continue; } .... } return new BigDecimal(number).doubleValue(); 

I'm sure that maybe this could have been improved, but I'm not quite sure if char supports non-literal letters.

+1
source

If you use Calligraphy , it solves your problem. apply your precision stuff to your text and this library will do the rest for you.

PS: you must use the correct Farsi font

0
source

Source: https://habr.com/ru/post/1242190/


All Articles