I want to convert an incoming Double
to String, where there is a thousand seperator.
For example 159727,5 should be 159 727,5
Here is my code:
public static String formatToHungraianNumber(Double toFormat) {
logger.info("formatToHungraianNumber begin :" + toFormat);
String formatted = toFormat.toString();
try {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator(' ');
DecimalFormat format = new DecimalFormat("# ###,00", symbols);
formatted = String.format("%14s", format.format(toFormat));
} catch (Exception e) {
logger.info("Runtime Exception", e);
return formatted;
}
logger.info("Returned:" + formatted);
return formatted;
}
Instead of return 159 727,5 it return 15 97 28 I had seen this question, but I DON't want my result to be Truncated. What is wrong with my code?