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?
Please, could you show an example of how to set all necessaries thing to use the client side Locale, in general, other than the local?
Now my code is:
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)) + ">"; string lFormat = "<DATA_VALUE:###,###,##0" + (cantidadDecimales == 0 ? "" : "." + lDecimales.Substring(0, cantidadDecimales)) + ">"; mGauge.Scales[0].Labels.FormatString = lFormat; }
numberDecimalSeparator and numberGroupSeparator are the separators I want use no matter the local machine locale.
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
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 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.
Yes!
This is what I need.
thank you