'Rule based number format - Indian currency
http://icu-project.org/apiref/icu4j/com/ibm/icu/text/RuleBasedNumberFormat.html
Using the above class,
def format = new RuleBasedNumberFormat(new Locale("en", "in"), RuleBasedNumberFormat.SPELLOUT)
format.format(value)
for ₹ 9,00,000 value, it shows nine hundred thousand
. But we have to show nine lakhs.
How to do this?
Solution 1:[1]
I dont think you will get that. As per the javadoc, this is the nomenclature they have... beyond thousand
1,000,000: << million[ >>];
1,000,000,000: << billion[ >>];
1,000,000,000,000: << trillion[ >>];
1,000,000,000,000,000: OUT OF RANGE!;
IMHO, you need to write custom logic. For e.g replace all "hundrend thousand" with lakh
Solution 2:[2]
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.text.RuleBasedNumberFormat;
public class StringDisplayUtils {
public static String toWords(Double num) {
return ((NumberFormat) (new RuleBasedNumberFormat(String.join("\n",
"Zero;One;Two;Three;Four;Five;Six;Seven;Eight;Nine;Ten;",
"Eleven;Twelve;Thirteen;Fourteen;Fifteen;Sixteen;Seventeen;Eighteen;Nineteen;",
"20: Twenty[ >>];",
"30: Thirty[ >>];",
"40: Forty[ >>];",
"50: Fifty[ >>];",
"60: Sixty[ >>];",
"70: Seventy[ >>];",
"80: Eighty[ >>];",
"90: Ninety[ >>];",
"1,00: << Hundred[ >>];",
"1,000: << Thousand[ >>];",
"1,000,00: << Lakh[ >>];",
"1,000,00,00: << Crore[ >>];",
"1,000,00,00,000,00,00,00: OUT OF RANGE!;"
)))).format(num);
}
}
this might help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hirak |
Solution 2 |