I am making a graphical calculator program in Java and have a method that performs an operation based on user input, and returns a double to be displayed in a JTextField. However, I would like the result to be displayed as a whole number, without a following ".0" where there are no significant digits after the decimal point, but still display decimal points when necessary. What’s the most efficient way of doing this?
I am making a graphical calculator program in Java and have a method that
Share
You can use
DecimalFormatfor suppressing the trailing characters, e.g.: