how to convert integer to bigdecimal in java

前端 未结 4 586
醉梦人生
醉梦人生 2020-12-09 14:46

I want to create a method that caculates multiplication an integer and a bigdecimal. I search on google and forums nothing I found.

import java.math.BigDecim         


        
4条回答
  •  醉梦人生
    2020-12-09 15:01

    These methods from the Java API will be helpful.

    public BigDecimal multiply​(BigDecimal multiplicand)
    

    Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()).

    Parameters: multiplicand - value to be multiplied by this BigDecimal. Returns: this * multiplicand

    public BigDecimal​(int val)
    

    Translates an int into a BigDecimal. The scale of the BigDecimal is zero.

    Parameters: val - int value to be converted to BigDecimal.

提交回复
热议问题