Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
BIRT SCRIPTING, ROUNDING ERROR
delee88
<p>8812.05 / 2, the answer is 4406.025 and rounded to 2 decimals should be displayed as 4406.03</p><p>Using either method below the result displays as 4406.02.</p><p> </p><p>Can anyone tell me what I need tp do to have the rounding work as I expected?</p><p> </p><p>- Thanks
Dale</p><p>1. this.text = df.format( 8812.05 / 2 ) </p><p>2. this.text = BirtMath.round(BirtMath.divide(8812.05 , 2), 2)</p><p> </p><p>
The procedure follows
</p><p>var vID3a = row["CompletedCounseling-ID3a"]
var vIEA = row["CompletedAmount-IE"]
var vIGA = row["CompletedAmount-IG"]
var nrf = row["NRF"]</p><p>var df = new Packages.java.text.DecimalFormat("#,###.##");</p><p>//var rm = new Packages.java.math.RoundingMode();</p><p>//df.setMinimumFractionDigits(2)
//df.setMaximumFractionDigits(2)
//df.setRoundingMode( rm.UP);</p><p>if (nrf == 0 )
{
this.text = "NRF"
}
else if ( vID3a == null|| vIEA == null && vIGA == null )
{
this.text = '###'
}
else if ( vID3a == 0 )
{
this.text = '$' + "0.00"
}
else
{
this.text = '$' + df.format( (vIEA + vIGA ) / vID3a )
// this.text = '$' + BirtMath.round(BirtMath.divide(vIEA + vIGA , vID3a), 2)</p><p> }</p>
Find more posts tagged with
Comments
wwilliams
<p>I tried this and it provided the result you want.</p><p>BirtMath.roundUp((8812.05/2),2) resulted in 4406.03</p>
delee88
<p><sub class='bbc'>Thanks</sub></p><p> </p><p><sub class='bbc'>But I only want to roundup if the number in the thousandths position is 5 or greater, otherwise I would want it to be rounded down.</sub></p><p> </p><p><sub class='bbc'>With roundUp 4406.001 would show as 4406.01 instead of 4406.00</sub></p>
wwilliams
<p>I used a parameter to test and it appears to do what you want.</p><p> </p><p>var remain = params["myValue"].value - Math.round( params["myValue"].value,2)</p><p>if( remain >= 5) {</p><p> </p><p>BirtMathroundUp( (params["myValue"].value),2);</p><p>}else{</p><p>BirtMathroundDown( (params["myValue"].value),2);</p><p>}</p>
delee88
<p>Thanks for the feedback. I may be able to use this approach.</p>