//"%.1f" this mean, how many number after the comma
String value = String.format("%.1f", 1654621658874684.0);
Be aware that double is not infinitely precise. It has a precision of about 15 to 17 decimal digits. If you need floating-point numbers with arbitrary precision, use BigDecimal instead of double.
You could use
String.format()
:String formatted = String.format("%f", dblNumber);
Format it appropriately. For example:
Or you can use it like a String:
Be aware that
double
is not infinitely precise. It has a precision of about 15 to 17 decimal digits. If you need floating-point numbers with arbitrary precision, useBigDecimal
instead ofdouble
.I use something like
long can have 18 digits whereas
double
has 15-16 digits of accuracy at best.