Created
May 14, 2019 03:51
-
-
Save esabook/8ba15afb03711caa91a4c094b995affd to your computer and use it in GitHub Desktop.
decimal formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Decimal Localization Format, like #,###.## for US or #.###,## for ID | |
* | |
* @param Numobj | |
* @return | |
*/ | |
//TODO: change to automatic localization detection | |
public static String DecimalFormater(Object Numobj) { | |
Object obj = String.valueOf(Numobj).matches("-?\\d+(\\.\\d+)?") ? Numobj : 0.00; | |
String digitPattern = Locale.getDefault().toString().equals("in_ID") ? "#.###.###,##" : "#,###,###.##"; | |
NumberFormat formatter = NumberFormat.getNumberInstance(Locale.getDefault()); | |
formatter.setRoundingMode(RoundingMode.HALF_EVEN); | |
formatter.setMaximumFractionDigits(2); | |
formatter.setMinimumFractionDigits(2); | |
return formatter.format(Float.parseFloat(obj.toString())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment