Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Created March 15, 2023 12:00
Show Gist options
  • Save Ankit-Slnk/d8de30c44f7cd60af35ab209ae2b7fda to your computer and use it in GitHub Desktop.
Save Ankit-Slnk/d8de30c44f7cd60af35ab209ae2b7fda to your computer and use it in GitHub Desktop.
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