0

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.

2 Answers 2

1

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();
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much Dinesh, you solved my problem! Have a nice day :)
0

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

1 Comment

The initial question was around extracting the Integer part of the double value. If you are really interested to ignore the decimal part after the division, you must just divide the double value after step 1 and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.