By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

Formatting with Decimal.ToString() ... CultureInfo and DigitGrouping...

P: n/a
Hi,

I have created CultureInfo object and specified required digit grouping in
it.
The one of the overloaded ToString methods of Decimal type has parameters to
format the value with required custom format and a IFormatProvider. I pass a
custom format string for positive, negative and Zero (3 sections) and
CultureInfo object containing the required DigitGrouping as IFormatProvider.
But ToString is not formatting the value using the digit grouping specified
in the CultureInfo object I passed. (however it is formatting the value
using 3 sections)

The only problem is... it is not using the DigitGrouping specified in the
CultureInfo. (I have correctly specified the format string to use the digit
grouping)

Any solutions?

Regards,
....Ashok
-------------------------------------------------------------
The greatest of all weaknesses is the fear of appearing weak.
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"G.Ashok" <gw******@hotmail.com> wrote
Hi,

I have created CultureInfo object and specified required digit grouping in
it.
The one of the overloaded ToString methods of Decimal type has parameters to
format the value with required custom format and a IFormatProvider. I pass a
custom format string for positive, negative and Zero (3 sections) and
CultureInfo object containing the required DigitGrouping as IFormatProvider.
But ToString is not formatting the value using the digit grouping specified
in the CultureInfo object I passed. (however it is formatting the value
using 3 sections)

The only problem is... it is not using the DigitGrouping specified in the
CultureInfo. (I have correctly specified the format string to use the digit
grouping)

Any solutions?

I have no solutions, and I don't work with culture info, (but there were
no other responses, so...) I just thought I would mention that I had
heard that to change the output, the thread's current culture had to be
set. But you seem to be passing in a CultureInfo object to a method.

What happens if you assign your object to the current culture?

System.Threading.Thread.CurrentThread.CurrentCultu re = YourCultureInfo
???

LFS

Nov 21 '05 #2

P: n/a
G. Ashok,

In addition to Larry,

Can you show maybe a piece of code, globalization is very easy, however what
is it what you want to display?

Or what you mean with a custom format string?
What is the culture (and language).
Normally the culture info helps to set a datetime or a value in the
representation of that culture, so how do you want it to be represented.

Maybe after some information about that we can help you.

Cor
Nov 21 '05 #3

P: n/a
Ashok,
It sounds like your custom format string is taking precedence, which makes
sense. As you are saying. "Here is the format I want to use"! Although I'm
not certain that is correct.

What happens when you call ToString supplying only your CultureInfo and a
standard format string? Do you get the standard format or your "digit
grouping".

As Cor asked, can you post the actual code you are using (10 to 15 lines
that demonstrates the problem is all we need). As I'm not seeing a
"DigitGrouping" property in CultureInfo or NumberFormatInfo.

Hope this helps
Jay
"G.Ashok" <gw******@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have created CultureInfo object and specified required digit grouping in
it.
The one of the overloaded ToString methods of Decimal type has parameters
to
format the value with required custom format and a IFormatProvider. I pass
a
custom format string for positive, negative and Zero (3 sections) and
CultureInfo object containing the required DigitGrouping as
IFormatProvider.
But ToString is not formatting the value using the digit grouping
specified
in the CultureInfo object I passed. (however it is formatting the value
using 3 sections)

The only problem is... it is not using the DigitGrouping specified in the
CultureInfo. (I have correctly specified the format string to use the
digit
grouping)

Any solutions?

Regards,
...Ashok
-------------------------------------------------------------
The greatest of all weaknesses is the fear of appearing weak.

Nov 21 '05 #4

P: n/a

"Rajesh Nandwani" <tr********@sancharnet.in> wrote

I am attaching sample. If you run the sample you will found 2 TextBoxes.
The first one in which I am interested. The second one has a standard
currency string and shows the result correctly.

It would help if you indicate what your desired result was.

When I enter 123456 and then leave, I see: Rs. 123,456.00
I don't know if that is what you expect or not....

LFS
Nov 21 '05 #5

P: n/a

"Rajesh Nandwani" <tr********@sancharnet.in> wrote

I am attaching sample. If you run the sample you will found 2 TextBoxes.
The first one in which I am interested. The second one has a standard
currency string and shows the result correctly.


Try this:

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

Me.MyCultureInfo.NumberFormat.CurrencyGroupSizes = New Integer() {3, 2}
Threading.Thread.CurrentThread.CurrentCulture = Me.MyCultureInfo

End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave

If Not IsNumeric(Me.TextBox1.Text) Then
Me.TextBox1.Text = "0"
End If

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("C")

End Sub

Nov 21 '05 #6

P: n/a
Dear Larry,

This does show the grouping if you include a standard currency format string
(That is what i showed in my sample in second TexBox2). But I want to set my
own format string (In TextBox1)

For example I wnat to my own format string like

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave

If Not IsNumeric(Me.TextBox1.Text) Then
Me.TextBox1.Text = "0"
End If

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("'Rs.'#,##0.00
CR;'Rs.'#,##0.00 DB;Zero")

End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

Me.MyCultureInfo.NumberFormat.CurrencyGroupSizes = New Integer() {3,
2}
Threading.Thread.CurrentThread.CurrentCulture = Me.MyCultureInfo

End Sub

Since I want to use the GroupingSizes (DigitGrouping) of the NumberFormat
in/with my custom format string as specified above, I have set my required
Currency Digit Grouping (CurrencyGroupSizes = New Integer() {3, 2}) and
passing in the parameter of the ToString() like this.

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("'Rs.'#,##0.00
CR;'Rs.'#,##0.00 DB;Zero", MyCultureInfo)

But the problem is it is not get used in the formatting of the above lline.

In short I want to specifiy a digit grouping (3,2) and it get it used in my
custom format string passed to Decimal's ToString().

Any Ideas?

Regards,
....Ashok
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eb**************@tk2msftngp13.phx.gbl...

"Rajesh Nandwani" <tr********@sancharnet.in> wrote

I am attaching sample. If you run the sample you will found 2 TextBoxes. The first one in which I am interested. The second one has a standard
currency string and shows the result correctly.
Try this:

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

Me.MyCultureInfo.NumberFormat.CurrencyGroupSizes = New Integer()

{3, 2} Threading.Thread.CurrentThread.CurrentCulture = Me.MyCultureInfo

End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
If Not IsNumeric(Me.TextBox1.Text) Then
Me.TextBox1.Text = "0"
End If

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("C")

End Sub

Nov 21 '05 #7

P: n/a
Rajesh,
Can you post 10 to 15 of code inline (cut & paste) in your message, not an
entire project in a zip file.

Along with the desired result as Larry stated...

For some reason I am not able to read your zip file.

Hope this helps
Jay

"Rajesh Nandwani" <tr********@sancharnet.in> wrote in message
news:OT**************@TK2MSFTNGP15.phx.gbl...
Thanks,

I am attaching sample. If you run the sample you will found 2 TextBoxes.
The first one in which I am interested. The second one has a standard
currency string and shows the result correctly.

Regards,
...Ashok

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Ashok,
It sounds like your custom format string is taking precedence, which
makes
sense. As you are saying. "Here is the format I want to use"! Although
I'm
not certain that is correct.

What happens when you call ToString supplying only your CultureInfo and a
standard format string? Do you get the standard format or your "digit
grouping".

As Cor asked, can you post the actual code you are using (10 to 15 lines
that demonstrates the problem is all we need). As I'm not seeing a
"DigitGrouping" property in CultureInfo or NumberFormatInfo.

Hope this helps
Jay
"G.Ashok" <gw******@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I have created CultureInfo object and specified required digit grouping in > it.
> The one of the overloaded ToString methods of Decimal type has parameters > to
> format the value with required custom format and a IFormatProvider. I pass > a
> custom format string for positive, negative and Zero (3 sections) and
> CultureInfo object containing the required DigitGrouping as
> IFormatProvider.
> But ToString is not formatting the value using the digit grouping
> specified
> in the CultureInfo object I passed. (however it is formatting the value
> using 3 sections)
>
> The only problem is... it is not using the DigitGrouping specified in the > CultureInfo. (I have correctly specified the format string to use the
> digit
> grouping)
>
> Any solutions?
>
> Regards,
> ...Ashok
> -------------------------------------------------------------
> The greatest of all weaknesses is the fear of appearing weak.
>
>



Nov 21 '05 #8

P: n/a
Jay,

Here the sample.

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave

If Not IsNumeric(Me.TextBox1.Text) Then
Me.TextBox1.Text = "0"
End If

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("'Rs.'#,##0.00
CR;'Rs.'#,##0.00 DB;Zero")

End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

Me.MyCultureInfo.NumberFormat.CurrencyGroupSizes = New Integer()
{3,2}
Threading.Thread.CurrentThread.CurrentCulture = Me.MyCultureInfo

End Sub

Since I want to use the GroupingSizes (DigitGrouping) of the NumberFormat
in/with my custom format string as specified above, I have set my required
Currency Digit Grouping (CurrencyGroupSizes = New Integer() {3, 2}) and
passing in the parameter of the ToString() like this.

Me.TextBox1.Text = CDec(Me.TextBox1.Text).ToString("'Rs.'#,##0.00
CR;'Rs.'#,##0.00 DB;Zero", MyCultureInfo)

But the problem is it is not get used in the formatting of the above lline.

In short I want to specifiy a digit grouping (3,2) and it get it used in my
custom format string passed to Decimal's ToString().

Any Ideas?

Regards,
....Ashok
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Rajesh,
Can you post 10 to 15 of code inline (cut & paste) in your message, not an
entire project in a zip file.

Along with the desired result as Larry stated...

For some reason I am not able to read your zip file.

Hope this helps
Jay

"Rajesh Nandwani" <tr********@sancharnet.in> wrote in message
news:OT**************@TK2MSFTNGP15.phx.gbl...
Thanks,

I am attaching sample. If you run the sample you will found 2 TextBoxes. The first one in which I am interested. The second one has a standard
currency string and shows the result correctly.

Regards,
...Ashok

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:uB**************@TK2MSFTNGP15.phx.gbl...
Ashok,
It sounds like your custom format string is taking precedence, which
makes
sense. As you are saying. "Here is the format I want to use"! Although
I'm
not certain that is correct.

What happens when you call ToString supplying only your CultureInfo and a standard format string? Do you get the standard format or your "digit
grouping".

As Cor asked, can you post the actual code you are using (10 to 15 lines that demonstrates the problem is all we need). As I'm not seeing a
"DigitGrouping" property in CultureInfo or NumberFormatInfo.

Hope this helps
Jay
"G.Ashok" <gw******@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I have created CultureInfo object and specified required digit grouping
in
> it.
> The one of the overloaded ToString methods of Decimal type has

parameters
> to
> format the value with required custom format and a IFormatProvider. I

pass
> a
> custom format string for positive, negative and Zero (3 sections) and
> CultureInfo object containing the required DigitGrouping as
> IFormatProvider.
> But ToString is not formatting the value using the digit grouping
> specified
> in the CultureInfo object I passed. (however it is formatting the

value > using 3 sections)
>
> The only problem is... it is not using the DigitGrouping specified in

the
> CultureInfo. (I have correctly specified the format string to use the
> digit
> grouping)
>
> Any solutions?
>
> Regards,
> ...Ashok
> -------------------------------------------------------------
> The greatest of all weaknesses is the fear of appearing weak.
>
>



Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.