Hi, I've been searching with no recents results, what is the way to set the Locale to numbers in an ultrawebgauge?
Thanks in advance
Hello Ricardo,
Appearance of the numbers in the gauge depends on the scale’s labels. If you need to format the numbers you should set FormatString of the labels. The format string should be set like this:
<DATA_VALUE:0>
If, for example you need to set currency format you may use this format string:
<DATA_VALUE:$# ##0.00>
Generally speaking format string consist of DATA_VALUE – this is the value coming from the component and .NET format string – this is what you can set as per your need.
Please let me know if this is what you are looking for or if I am missing something.
So, how can I set the format with client side locale, in a dynamically server side created gauge?
Hi, I made further research and found this:
1- With .Scales[0].Labels.FormatString not set
2- With .Scales[0].Labels.FormatString set to "<DATA_VALUE:###.###.##0,00>" (spanish locale)
It seems there's no way to set "." as decimal group and "," as decimal separator. It is that correct?
Yes!
This is what I need.
thank you
Hi Ricardo,
I was wrongly thought you need to set some custom format for each locale. Looking at your code it seems that you need to set standard numeric format with predefined precision after decimal point – cantidadDecimales in your case. To do this, regardless of the culture, you may use code like this:
public void SetScaleLabelFormat(int cantidadDecimales) { // Get the culture info from the request and set it to current culture var ci = this.CultureInfoFromRequest(Request); System.Threading.Thread.CurrentThread.CurrentCulture = ci; // use Nxxx number format with xxx equal to your cantidadDecimales string lFormat = "<DATA_VALUE:N" + cantidadDecimales + ">"; mGauge.Scales[0].Labels.FormatString = lFormat; }
Please test this and let me know if this solves your issue.
Effectively:
var lCulture = new CultureInfo(Manager.Culture); mGauge.SetScaleLabelFormat(lCulture.NumberFormat.CurrencyDecimalSeparator, lCulture.NumberFormat.CurrencyGroupSeparator, ((clsIndicadorUICtrlGauge)mConfigVisual.Indicadores.Item(0)).CantidadDecimales); public void SetScaleLabelFormat(string numberDecimalSeparator, string numberGroupSeparator, int cantidadDecimales) { string lDecimales = "0000000000"; string lFormat = "<DATA_VALUE:###" + numberGroupSeparator + "###" + numberGroupSeparator + "##0" + (cantidadDecimales == 0 ? "" : numberDecimalSeparator + lDecimales.Substring(0, cantidadDecimales)) + ">"; mGauge.Scales[0].Labels.FormatString = lFormat; }
Only Works correctly if the format is:
string lFormat = "<DATA_VALUE:###,###,##0" + (cantidadDecimales == 0 ? "" : "." + lDecimales.Substring(0, cantidadDecimales)) + ">";
and I supose it takes the locale of the local machine.
Hi Milko, but is what i do, numberDecimalSeparator and numberGroupSeparator are taken from the request:
var lCulture = new CultureInfo(Manager.Culture); mGauge.SetScaleLabelFormat(lCulture.NumberFormat.NumberDecimalSeparator, lCulture.NumberFormat.NumberGroupSeparator, ((clsIndicadorUICtrlGauge)mConfigVisual.Indicadores.Item(0)).CantidadDecimales);
Manager.Culture= Request.UserLanguages[0]
But, when this is spanish then DecimalSeparator=";" and NumberGroupSeparator="." you saw the result in my first post, second image.
Is there something I'm missing?
Thank you in advance
To use the user locale you should first try to get it from the request. You may use code like this:
public CultureInfo CultureInfoFromRequest(HttpRequest request) { var ci = System.Globalization.CultureInfo.InvariantCulture; if (request.UserLanguages != null && request.UserLanguages.Length > 0) { try { ci = new CultureInfo(request.UserLanguages[0]); } catch (Exception) { } } return ci; }
Then you can change a little your SetScaleLabelFormat method like this:
public void SetScaleLabelFormat(string numberDecimalSeparator, string numberGroupSeparator, int cantidadDecimales) { string lDecimales = "0000000000"; // Get the culture info from the request var ci = this.CultureInfoFromRequest(Request); //string lFormat = "<DATA_VALUE:###" + numberGroupSeparator + "###" + numberGroupSeparator + "##0" + (cantidadDecimales == 0 ? "" : numberDecimalSeparator + lDecimales.Substring(0, cantidadDecimales)) + ">"; // use CurrencyDecimalSeparator from the culture info you retrieved from the request string lFormat = "<DATA_VALUE:###,###,##0" + (cantidadDecimales == 0 ? "" : ci.NumberFormat.CurrencyDecimalSeparator + lDecimales.Substring(0, cantidadDecimales)) + ">"; mGauge.Scales[0].Labels.FormatString = lFormat; }
Please let me know if you need any further assistance on this matter.