I'm developing an ASP.NET MVC 3 app that uses both jQuery Globalization and jQuery UI Slider.
I'm localizing this app to Portuguese from Brazil (pt-BR) and it also supports English.
The problem is that when I change the language to Portuguese, all Model float
values come delimited by a comma ( , ) like 7,7. I then try to set the Slider initial value but it only accepts the value with a dot ( . ) like 7.7.
To overcome such situation I'm doing this:
$.CreateSlider("#sliderHeight", "#Height", @Model.Height.FormatValue(), 0, 2.5, 0.01);
FormatValue is an extension method:
public static string FormatValue(this float value)
{
return value.Value.ToString().Replace(",", ".");
}
You see that I have to replace the comma delimiter with a dot delimiter so that I can set the jQuery Slider value.
I then have to use jQuery Globalization to show the correct value in the UI this way:
$(textBox).val($.global.format(ui.value, 'n2'));
It works at least...
My question is:
Is there a better or standard way of doing this?
The thing is that the Model values are coming the way they should, that is, as I switched the culture to pt-BR the numbers come ( , ) delimited. This is correct in my point of view. The limitation is in the way the jQuery Slider receives the value.
Just to complement: if I tried to pass the values the way they come from the @Model
, I'd have something like this, that obviously would break (because the parameters values are themselves separated by commas):
$.CreateSlider("#sliderHeight", "#Height", 7,7 , 0, 2.5, 0.01);