Xpage Math.round - display trailing zero

I am using the following computed code on a label:

return “$” + Math.round(totalMiles / totalGas * 100) / 100;

This works great for numbers like $1.23, but for $1.50 it just displays as $1.5.

Is there some preference or setting I am missing? Any help is appreciated.

Subject: You’re writing a string

to a label I believe, so a string will be whatever you right to it. So this code for example:var original=150;

alert(Math.round(original*100)/100) //displays 150

original = 24.35

alert(Math.round(original*100)/100) //displays 24.35

So you need to check the string after you convert it.

I found the following function via google Use JavaScript to Format Currency within Your Web Page

function CurrencyFormatted(amount)

{

var i = parseFloat(amount);

if(isNaN(i)) { i = 0.00; }

var minus = '';

if(i < 0) { minus = '-'; }

i = Math.abs(i);

i = parseInt((i + .005) * 100);

i = i / 100;

s = new String(i);

if(s.indexOf('.') < 0) { s += '.00'; }

if(s.indexOf('.') == (s.length - 2)) { s += '0'; }

s = minus + s;

return s;

}

// end of function CurrencyFormatted()

var original=150;

alert(CurrencyFormatted(original)) //displays 150.00

original = 24.35

alert(CurrencyFormatted(original)) //displays 24.35

If it was a number field, you could set the display type.

Subject: Solved - Thank you

Thanks Carl. I was aware of the setting on a number field, but didn’t realize what was happening with the label. That function worked great.