开发者

Converting string to bigdecimal in ireport

开发者 https://www.devze.com 2023-02-11 02:49 出处:网络
How do I convert following String output into BigDecimal? new java.text.DecimalFormat(\"#,开发者_StackOverflow##0.00\").format(
  1. How do I convert following String output into BigDecimal?

    new java.text.DecimalFormat("#,开发者_StackOverflow##0.00").format(
      new Double((
        $V{xHrAdm}.doubleValue()*$V{xHrAdm}.doubleValue() +
        $V{xFodaBnB}.doubleValue()*$V{xFodaBnB}.doubleValue() +
        $V{xChem}.doubleValue()*$V{xChem}.doubleValue() +
        $V{xSCMnQA}.doubleValue()*$V{xSCMnQA}.doubleValue() + 
        $V{xPCO}.doubleValue()*$V{xPCO}.doubleValue() +
        $V{xComp.Eng}.doubleValue() * $V{xComp.Eng}.doubleValue()) / 6))
    
  2. I also want the square root of the above expression


1.) Why do you need to convert it to String first and then to BigDecimal? You could convert it directly to BigDecimal using the double constructor like this:

new BigDecimal(
$V{xHrAdm}.doubleValue()*$V{xHrAdm}.doubleValue() +
$V{xFodaBnB}.doubleValue()*$V{xFodaBnB}.doubleValue() +
$V{xChem}.doubleValue()*$V{xChem}.doubleValue() +
$V{xSCMnQA}.doubleValue()*$V{xSCMnQA}.doubleValue() + 
$V{xPCO}.doubleValue()*$V{xPCO}.doubleValue() +
$V{xComp.Eng}.doubleValue() * $V{xComp.Eng}.doubleValue()) / 6)

And then apply the format to the cell.

2.) To get the square root you can use the sqrt method of the Math class like this:

new BigDecimal(
Math.sqrt(
$V{xHrAdm}.doubleValue()*$V{xHrAdm}.doubleValue() +
$V{xFodaBnB}.doubleValue()*$V{xFodaBnB}.doubleValue() +
$V{xChem}.doubleValue()*$V{xChem}.doubleValue() +
$V{xSCMnQA}.doubleValue()*$V{xSCMnQA}.doubleValue() + 
$V{xPCO}.doubleValue()*$V{xPCO}.doubleValue() +
$V{xComp.Eng}.doubleValue() * $V{xComp.Eng}.doubleValue()) / 6))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号