开发者

ToString() format is not working

I've a strange problem. We use Dutch and French lanuage on our site (nl-NL / fr-FR)

I'm binding to a gridview and the strange thing is, the numeric value-saparator (dot) is not displaying well for French (fr-FR)

ASP.NET

protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
    Label lbla_min_10 = new Label();
    lbla_min_10 = e.Row.FindControl("lbla_min_10") as Label;
    lbla_min_10.Text = ((int)DataBinder.Eval(e.Row.DataItem, "a_min_10")).ToString("#,#.###");
    //....
}

e.g. DB value is 24369

in Dutch it displays 24.369 and

in French it displays 24 369 -> there is no DOT separator, but an empty space.

I looked at the view source and the code looks the same excep开发者_运维问答t theres is a (dot) in NL and (space) in FR.....

Does someone have any idea?

why does it work for Dutch (nl-NL) fine and not for French (fr-FR)?


Try using "nl-BE" and "fr-BE". They use the same formatting when it comes to numbers.

String.Format("{0:##,###}", 12345); // nl-NL: 12.345
String.Format("{0:##,###}", 12345); // fr-FR: 12 345
String.Format("{0:##,###}", 12345); // nl-BE: 12.345
String.Format("{0:##,###}", 12345); // fr-BE: 12.345


That's how the french denote thousands. with a space. The dutch use a .(full stop), the Engish use a , (comma).

So the regional formatting is working as expected.


In the 'Fr Culture' there is no separator between 1000's and 100's. So if you write 10.000 in dutch you can write 10 000 in french.. Why is it a problem?


Well, it behaves correctly. The problem is, what you actually used is grouping (thousands) separator. If you want it to be formatted always with full stop, add CultureInfo.InvariantCulture as second parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜