mamba
mamba

Reputation: 25

BIRT - Javascript Math.abs function not working

I have the following data expression in a cell from a table:

var abs_number = Math.abs(row["per"]);

if (abs_number >= vars["Tripped"]) {
    'Y (>' + vars["Tripped"] + '%)';
} else {
    'N (<' + vars["Tripped"] + '%)';
}

The problem is, if row["per"] == -51.20 and vars["Tripped"] == 4; then this script returns

'N (<' + vars["Tripped"] + '%)'

Ideally, if the absolute number is > 4, it should return

'Y (>' + vars["Tripped"] + '%)';

EDIT: The issue was on the way I was setting up the row["per"] variable. Please close or ignore this question. Thanks!

Upvotes: 1

Views: 2583

Answers (2)

Brooks Lybrand
Brooks Lybrand

Reputation: 91

This should be working. If you plug in your values it does what you want. Do you know for sure that row["per"] and vars["Tripped"] are returning what you want them to?

Upvotes: 0

a8hok
a8hok

Reputation: 308

It retuns 'Y (>' + 4 + '%)', it works fine, check the snippet

var abs_number = Math.abs(-51.20);

if (abs_number >= 4) {
    console.log('Y (>' + 4 + '%)');
} else {
    console.log('N (<' + 4 + '%)');
}

Upvotes: 1

Related Questions