Formatting number to currency with ICU for use in Google Column Chart
I'm using Google Charts in order to开发者_如何转开发 make a nice columns chart, its actually a pretty easy task but I got stuck at the following point: I gotta format the values showed at the vertical axis this way -> "R$ 1.000,00" (for Brazilian currency), I then found at googles documentation page about columns charts that its possible to supply an ICU expression to format the number the way I want, including currency formatting.
--------------------------------| ICU SYNTAX BELOW |
vAxis: {title: 'VALUES', format: 'R\u00A4 #.###0,00'}
This was the closest I could get, but this expression gives me:
1000 -> R$ 1000.00 when it should be R$ 1.000,00
So my two problems are:
1) Cant get the thousand separator to show 2) Cant replace thousand separator by "." and decimal separator by ","
googled the web and found lots of stuff regarding ICU itself, describing how to achieve it by calling some methods from ICU C++ lib, but its obviously not available when dealing w/ google charts.
By your question, I can imagine you are a Brazilian. So, you should look at how set the locale for Google Charts first:
http://code.google.com/apis/chart/interactive/docs/library_loading_enhancements.html#loadwithlocale
After, you should set your format as an ICU format:
http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
EDIT:
- locale: pt_BR
- format: '¤ #,##0.00'
That should do it for you. :)
In the formatting specifier you should use 'R\u00A4 #,###0.00'. ,
means grouping, .
means decimal. It's just a pattern. You need to specify that the grouping and decimal characters are the ones you like by another mechanism.
With the new API, it is now possible to get the currency format.
For column charts, you can try
vAxis: {format: 'currency'}
.
精彩评论