开发者

Problem with AutoValidate when using format string on negative numbers

I've got this format string "### ### ### ##0.00". It works well for positive number. But when I got negative number (for example -23.6), than I returns "- 23.60". That cause problem with AutoValidate on TextBox. I need to remove the three space between minus sign and number (spaces between numbers are no problem for validato开发者_如何学JAVAr). Which format string I have to use, to preserve format for positive numbers but which remove spaces between minus sign and number in negative numbers? For example if I got -1234567, then It gives me -1 234 567.00? I'm using .NET 2.0


Can you consider using a comma instead of space in format string:

String.Format("###,###,###,##0.00", -23.60);   

instead of

String.Format("### ### ### ##0.00", -23.60);   

EDIT to handle CZECH Culture Info

CultureInfo culture = CultureInfo.CreateSpecificCulture("cs-CZ");
String.Format("###,###,###,##0.00", -23.60, culture);   // outputs: -23,60
String.Format("###,###,###,##0.00", -123.60, culture);   // outputs: -123,60
String.Format("###,###,###,##0.00", -23.60, culture);   // outputs: -1 23,60


Try this:

Val(TextBox1.Text).ToString("#,#").Replace(",", " ")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜