Field Render to trim trailing zeroes?

  • 1
  • Question
  • Updated 5 years ago
  • Answered
I'm trying to get a number field to display as currency, but with a custom number of places after the decimal. Essentially trying to trim the trailing zeroes for display purposes. Here's my code but it doesn't work. The field is defined with 8 decimals and it always displays with 8 decimals regardless of the actual value:



var field = arguments[0];
var value = arguments[1];
field.element.css({'text-align': 'right'});
if (value == null || value == 0) {
skuid.ui.fieldRenderers.CURRENCY[field.mode](field,value);
} else {
value = value.toString();
var valLen = value.length;
var displayValue = (Number(value).toFixed(valLen-2));
skuid.ui.fieldRenderers.CURRENCY[field.mode](field,displayValue);
}
Photo of Jonathan Adlerstein

Jonathan Adlerstein

  • 528 Points 500 badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This should do it.




var NUMBER_OF_DECIMAL_PLACES = 2;

var field = arguments[0];
var value = arguments[1];
field.element.css({'text-align': 'right'});
if (value == null || value == 0) {
skuid.ui.fieldRenderers.CURRENCY[field.mode](field,value);
} else {
field.metadata.scale = NUMBER_OF_DECIMAL_PLACES;
skuid.ui.fieldRenderers.CURRENCY[field.mode](field,value);
}

Photo of Jonathan Adlerstein

Jonathan Adlerstein

  • 528 Points 500 badge 2x thumb
Worked, thanks!