Skip to content

Instantly share code, notes, and snippets.

@adojos
Created December 30, 2021 16:28
Show Gist options
  • Save adojos/b8c17d2e8b2af4b43df92c35de7031e8 to your computer and use it in GitHub Desktop.
Save adojos/b8c17d2e8b2af4b43df92c35de7031e8 to your computer and use it in GitHub Desktop.
Java: Format Decimal with String Literals #java
import java.text.DecimalFormat;
public class DecimalFormatAndStringLiteral {
public static void main(String[] args) {
double dbNum = 170180.24551D;
String strPattern = "My formatted number is #,###.###";
DecimalFormat deciFormat = new DecimalFormat(strPattern);
String strFormattedNum = deciFormat.format(dbNum);
System.out.println(strFormattedNum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment