Good afternoon, tell me, please ... how to form and save the amount of 123.00 using BigDecimal, if you transferred it as 123?

I did not find any similar formatters, I will be grateful for the help.

  • Do you then output this field to String? - Chubatiy
  • Yes, there is a public static String toString (BigDecimal bigDecimal) {DecimalFormat numFormat; String number; numFormat = new DecimalFormat (". 00"); number = numFormat.format (bigDecimal); return number; } ', the problem is that the client can send amounts without values ​​after . , and on the server side a digital signature is formed taking into account the amounts - andy
  • So you just wrote yourself how to solve your question. What is the question then?) Do you need to have a pair of zeros at the end or not? - Chubatiy
  • Exactly!)), And used String.valueOf .... Thank you!)) - andy
  • Not at all) They themselves asked the question themselves answered. The Miracles of Automation - Chubatiy

2 answers 2

Thanks to all. Solved. For saving in the String format, the formatter is suitable:

public static String toString(BigDecimal bigDecimal) { DecimalFormat numFormat; String number; numFormat = new DecimalFormat(".00"); number = numFormat.format(bigDecimal); return number; } 
     new BigDecimal("123.00").setScale(2, RoundingMode.HALF_UP); 
    • one
      Probably wanted to write new BigDecimal("123").setScale... - Sergey
    • one
      @Sergey you are right. wanted to - Senior Pomidor