How do I format negative numbers in Yellowfin?

A formatter for formatting negative numbers as zero is outlined below. You will need to install and customize the binary JAR file below. This is a simple formatter which is a good candidate for showing how these work. 

Note the negative numbers are formatted as zero.

Here is the source code to this formatter:

package com.example.formatter;

import java.text.DecimalFormat;

import java.text.NumberFormat;

import com.hof.mi.interfaces.CustomFormatter;

public class ZeroFormatter extends CustomFormatter {

public String getName() {

return "Zero Fromatter";

}

public boolean acceptsNativeType(int type) {

return type == TYPE_NUMERIC;

}

public String render(Object data, int renderType) {

if (data!=null && data instanceof Number) {

float number = ((Number) data).floatValue();

if (number <= 0) {

return "0";

} else {

NumberFormat nf = new DecimalFormat();

nf.setMaximumFractionDigits(0);

nf.setGroupingUsed(true);

return "+" + nf.format(data);

}

}

return null;

}

}

Basically, for each row of data render (data, renderType) is called. Data is the raw data to be displayed, you can manipulate this as you like and return a string of the rendered value. To develop these yourself you will need to include the i4-core.jar file from the Yellowfin/appserver/webapps/ROOT/WEB-INF/lib directory as a compilation dependency.

Content Owner: Peter D

Localedge Project

Is article helpful?