format(number, "formatstring") wierdness

chris1028

Newcomer
Joined
Sep 23, 2009
Messages
8
Hi,

Here's a short command-line exchange:

>? format(10000/3, "#\,##0.00")
"3,333.33"
>? format(10000/3, "#\,##0\.00")
",33.33"

eh?
What happened when I escaped the dot with \. ???

Chris
VS2008/VB.net
 
Why?

I'm trying to globalize MS reportviewer ...the stupid thing ignores regionalsettings (so you get US dates (mm/dd/yyyy) and US numbers (1,234.56) independent of your settings)

Dates are now under control!

Numbers are more problematic - I need to handle user preferences including:

1'234.56

1'234,56

1,234.56

1.234,56

It is easy to format a number (10000/3) in user-preference "n", and parse out the separators - but how to force these separators into a custom formatstring?

Chris
 
Can you specify a culture in the ToString and Parse methods of numeric types to parse and output (or convert) the right formatting? For example, if you need to convert to the local culture, use Decimal.TryParse (or float/double) with an invarant culture, then Decimal.ToString with the local culture?
 
Thanks for your reply.

I've seen several mentions of the culture approach on the web, but this doesn't seem to be the route I'm looking for - culture is stuffed full of MS presumptions ...just because a user's setup is based on a certain culture doesn't prevent that user from having made personal modifs to regional settings.

I gave up: all users will now see 1'234.56 on their reports.

Chris
 
Back
Top