-
February 16th, 2010, 01:47 PM
#1
Modifying Decimal Places Displayed
Hi,
I have created a page that displays foreign exchange rates with 6 decimal places, such as GBP 1.654321 and I want to display only 4. The code that I’ve added is shown below, but it does not have any effect on the resulting display.
Thanks.
//added to format decimal places
pushtable.onChangingValues = formatValues;
//copied from StockListDemo
//WDX is name of field in schema that requires formatting
function formatValues(item, itemUpdate) {
if (itemUpdate == null) return;
var newValue = itemUpdate.getFormattedValue("WDX");
if (newValue != null) {
var formattedVal = formatDecimal(newValue, 4, true);
itemUpdate.setFormattedValue("WDX",formattedVal);
}
}
// format a decimal number to a fixed number of decimals
function formatDecimal(value, decimals, keepZero) {
var mul = new String("1");
var zero = new String("0");
for (var i = decimals; i > 0; i--) {
mul += zero;
}
value = Math.round(value * mul);
value = value / mul;
var strVal = new String(value);
if (!keepZero) {
return strVal;
}
var nowDecimals = 0;
var dot = strVal.indexOf(".");
if (dot == -1) {
strVal += ".";
} else {
nowDecimals = strVal.length - dot - 1;
}
for (var i = nowDecimals; i < decimals; i++) {
strVal = strVal + zero;
}
return strVal;
}
-
February 16th, 2010, 03:18 PM
#2
I have just discovered that the code for the decimal formatting is working. However, the code below appears to void the formatting. Any suggestions.
pushtable.onChangingValues = function(itemPos, visualUpdateInfo, itemName) {
function formatHighlites(itemPos, visualUpdateInfo, itemName) {
if (visualUpdateInfo != null) {
var cold = (itemPos % 2 == 1) ? "#eeeeee" : "#ddddee";
visualUpdateInfo.setRowAttribute("lightblue", cold, "backgroundColor");
}
}
-
February 17th, 2010, 09:18 AM
#3
Hi,
if there are no typos in your second message, you don't execute anything in your handler, you just declare a function there and you also miss a }
Moreover in the second post there is no call to the formatDecimal method.
Finally, if the code in both posts is in the same page, you're writing the onChangingValues callback two times, so that the first assignment is overwritten by the second one
Probably your onChangingValues assignment should look like this:
-
February 17th, 2010, 10:38 AM
#4
Hi,
Thank-you for the prompt reply. I realised, through further testing last night, that the second onChangingValue call was overwritting the first. Then I struggled with creating the call that you have provided. This works perfectly and this thread is closed.
Thanks, Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
All times are GMT +1. The time now is 07:50 AM.
Bookmarks