Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to call the Java Script within Render()
raghu1241
Hi,
I have a requirement to call the java script function within the render() of field data for rounding the number to two decimal points.
When I tried to call the java script I am getting an error.
Can any one help me.
regards,
Raghu.
Find more posts tagged with
Comments
mwilliams
Hi Raghu,
Where are you putting this script? What script are you using? And what is the error that you get? Can you post the stack trace? Thanks!
raghu1241
Thanks for the reply.
I have a aggregated field with float datatype which will sum up the value.While displaying the data we want to format it two decimal point.
eg: 10000.031 + 13999.962 + 10000.032 + 13999.961 = 47999.986
when I formatted the number its display 47999.99 but not 47999.98
To achieve this I have written a javascript function in js file.
When called from onRender() of aggregated field got an unhandled exception while executing script.
this.setDisplayValue(format_ScriptNumber(this.getValue()))
function format_ScriptNumber(numData){
if(numData != null){
objData = '0.00';
temp = parseFloat(numData);
if(temp < 0){
numData *= -1;
}
objArr = numData.toString().split('\\.');
if(objArr.length > 1){
objData = Comma(objArr[0]);
if(objArr[1].length() > 1){
objData += '.' + objArr[1].substring(0,2);
}else{
objData += '.' + objArr[1] + '0';
}
}else{
objData = Comma(objArr[0]);
objData += '.' + '00';
}
if(temp < 0){
objData = '(' + objData + ')';
}
return objData;
}else{
return numData;
}
}
// It will return the comma separated value
function Comma(number) {
number = '' + number;
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}
Please help me.
Regards,
Raghu.
mwilliams
Raghu,
So, when you format the float field to 2 decimal points in BIRT, you get the wrong rounding?
If using a js file, did you add the file as a resource in the property editor for the report?
CBR
Why not using the rounding mode on the number format?