In Google Visualization number format when having negative money how can I have the minus sign before the dollar sign

StackOverflow https://stackoverflow.com/questions/20642632

Domanda

I have a column full of numbers I need to format as cash. The number formatting works except when I have a negative number it returns $- instead of -$. Is there a way to fix this?

var formatter = new google.visualization.NumberFormat(
{ pattern: "$###,##0.00"});
formatter.format(tableData,1);
È stato utile?

Soluzione

The ISO patterns support specifying a negative number pattern so you can change the default handling of negative numbers. The negative pattern follows all the same rules as the positive pattern, but no negative sign is applied automatically, you must specify it as part of the pattern (this allows for using culture-specific negative patterns or task-specific negative patterns). In your case, the negative pattern would look like this:

"-$###,##0.00"

To combine the patterns, separate them with a ; in the pattern string: "<positive pattern>;<negative pattern>". Your pattern string would look like this:

"$###,##0.00;-$###,##0.00"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top