R
R
RichardXXX2019-02-27 19:00:37
Java
RichardXXX, 2019-02-27 19:00:37

How to add spaces to a string and reduce numbers after a comma?

At the input to the method, a string like 3125126.356356356 is supplied

public static String mySplit(String string) {
        String str = null;
        str = String.format("%.3f", Double.parseDouble(string));
        return str;
   }

at the output we get 3125126.356 It is
necessary to get 3 125 126.356
That is, add spaces to the left side before the decimal point so that thousandths can be visually determined in the program

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-02-27
@zagayevskiy

I think one can use DecimalFormat + DecimalFormatSymbols::setDecimalSeparator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question