Double tCountDouble = Double.parseDouble(String.valueOf(recieveTCount)); Double towPrDouble = Double.parseDouble(towPr); Double sumTaskDouble = towPrDouble * tCountDouble; String sumTask = String.valueOf(sumTaskDouble); 

And then sumTask goes to TextView.

 tv.setText(sumTask); 

But since sumTask is the result of multiplication, the result is 1234.0 or 1234.98 . It is necessary to break the whole part.

It is necessary to obtain from the result 7845.0 the following - 7 845.0

  • String.format to help you - Chad 2:49
  • Yes, I know about ticks. - web_alex

2 answers 2

 DecimalFormat df = new DecimalFormat(); df.setGroupingUsed(true); df.setGroupingSize(3); DecimalFormatSymbols decimalFormatSymbols = getDecimalFormatSymbols(); decimalFormatSymbols.setDecimalSeparator('.'); decimalFormatSymbols.setGroupingSeparator(' '); df.setDecimalFormatSymbols(decimalFormatSymbols); String sample = df.format(1023.3443d) 
  • And can a little explanation to the code? - web_alex 1:58
  • @Andreich, the separation is correct, but zeros are output. brought to the log. received the following: 0 000 000.0 and the line was: 2527968.0 - web_alex
  • one
    @web_alex I do not understand what your problem is. take.ms/fUiZ2 Can you give an example of your use? - andreich
  • @Andreich, the code is in question. Next, you need to split sumTask, if it is 3-digit. Your code always output zeros. That is, for example, the number 123900.0 he presented as 000 000.0. Broken correctly, but the numbers are not the same. And then completely refused to display zeros. Poured some random numbers of the correct order. - web_alex
  • one
    @web_alex, no complaints) The answer @Andreich, of course, is more correct. - Yuriy SPb

But I built such a bike:

 String sumTask = "7123261836287368246192391273845.0"; //сначала ставим первый пробел перед точкой. //находим индекс точки в строке int pointPosition = sumTask.indexOf("."); //вставим первый пробел, разделив строку на две части (до и после точки) и склеив обратно. sumTask = sumTask.substring(0, pointPosition - 3) + " " + sumTask.substring(pointPosition - 3); //теперь от пробела к началу строки ставим остальные пробелы for (int i = 0; i < pointPosition / 3; i++) { //находим последний вставленный пробел int lastSpacePosition = sumTask.indexOf(" "); //проверяем, не выйдем ли мы за пределы строки, вставляя новый. Если да - завершаем цикл. if((lastSpacePosition - 3)>0) { sumTask = sumTask.substring(0, lastSpacePosition - 3) + " " + sumTask.substring(lastSpacePosition - 3); } else { break; } } System.out.println(sumTask); 

Displays: 7 123 261 836 287 368 246 192 391 273 845.0

The answer @Andreich , of course, is more elegant, but I began to answer even before the publication of his answer)