Gianluca
Gianluca

Reputation: 15

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.

Upvotes: 0

Views: 781

Answers (2)

PAV
PAV

Reputation: 1

Thanks guys! I was in need of the same exact thing :D I guess we are having troubles editing the same software (Fattura24).

I wanted to ask @Dinesh how would I then divide this integer by a set number?

E.g. I have $F{quantita} (which contains the double value if not converted to integer) and I need to display the result of its division by 4. So the output has to be the integer result of $F{quantita} /4. How can I achieve this? Thank you for your help

Upvotes: 0

Dinesh Acharya
Dinesh Acharya

Reputation: 135

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();
    

Upvotes: 1

Related Questions