Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Created March 15, 2023 12:00
Fix decimal format for price
public static String getDecimalFormat(double value) {
String newValue = new DecimalFormat("#.##").format(value);
if (!newValue.contains(".")) {
return newValue + ".00";
} else {
return newValue.split("\\.")[1].length() == 1 ? (newValue + "0") : newValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment