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
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.