[Java] Type conversion from java BigDecimal type to String type

less than 1 minute read

It seems that java originally has a class called BigDecimal.

For the first time, declare a variable of type BigDecimal, When I finally wanted to convert a BigDecimal type variable to a String type, I thought that I should use the valueOf() method, but BigDecimal seems to have a method for type conversion.

sample Screenshots 2020-06-10 16.09.28.png

First of all, the BigDecimal type variable declaration & initialization is done at the top. There are 3 variables (right, left, decimalValue) in all. Next, store the calculation results of right and left in decimalValue with a switch statement. And the type conversion, which is the point of interest, String decimalValue1 = decimalValue.toString(); Is performing type conversion. First, prepare decimalVlue1 to put the converted value Next, I convert the decimalValue using the method that BigDecimal called toString() has.