What is the best way to convert a double to String without decimal places?
What about String.valueOf((int) documentNumber)?
The doubles always have 0 after the decimal dot. I don't need to round or truncate
If you are sure that the double is indeed an integer use this one:
NumberFormat nf = DecimalFormat.getInstance();
nf.setMaximumFractionDigits(0);
String str = nf.format(documentNumber);
As a bonus, this way you keep your locale's configuration as in thousand separator.
EDIT
I add this previously removed option as it seems that was useful to the OP:
Double.valueOf(documentNumber).intValue();
You could try this:
String numWihoutDecimal = String.valueOf(documentNumber).split("\\.")[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With