473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
8 9135

"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
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
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

"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

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
1
by: Plunaldo | last post by:
I have some questions about Numberformatting What is the best way to format a number that will be shown to a user? is it CultureInfo cultureInfo = CultureInfo.CurrentCulture...
2
by: Earl | last post by:
Still trying to clean up some datagrid formatting issues from the past. When I bring in money values from a stored procedure, I'm getting 4 decimal places in the grid ( which of course I only...
8
by: Rico | last post by:
Hello Everyone, I observed something strange in some quick testing code: void Button1Click(object sender, System.EventArgs e) { CultureInfo culture = new CultureInfo("th-TH", false); ...
14
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
8
by: =?Utf-8?B?T2xpdmllciBHSUw=?= | last post by:
Hello, I try to convert a volume stored as a string value in an XML file into a Decimal object. The volume is stored with comma as decimal separator ("210,12") according to french habits. To be...
9
by: David Jackson | last post by:
Hello, Is there anything in the framework which will format a date to show the ordinal representation of the day value e.g. 28th June 2007 1st August 2007 instead of
8
by: Mihai N. | last post by:
I need to format any decimal value so that it is right aligned, thousands It is good to show the info in the format the user prefers. That is language/locale speciffic (CultureInfo in the .NET...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.