Search code examples
javaintegerdouble

How to display an integer value instead of a decimal value


I have this string:

$V{Formatter}.format(new Double($F{quantita}.replaceAll(",",".")))+" " + $F{unitaDiMisura}

that serves to display a number on a document, based on the value that the user digits on his control panel.

With this string, if the user digits "1", in the document appears "1,00".

What do I need to do if I don't want the decimals to be displayed? Example: if the user digits "1", I want that in the document is displayed "1".

Sorry if something is not understandable, I'm not a developer...

Thanks in advance to everyone who will help.


Solution

  • You have to convert the double value to integer type.

    I assume $F{quantita} contains the double value (in String) then,

    String.valueOf(Double.valueOf($F{quantita}).intValue())
    

    Above line can be split down like below.

    1. Create a Double value from String.
       Double value = Double.valueOf($F{quantita});
      
    2. extract the Integer portion from double value.
      Integer intValue = value.intValue();
      
    3. Convert to String using toString().
      intValue.toString();