473,574 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting with Decimal.ToStrin g() ... 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 9163

"G.Ashok" <gw******@hotma il.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.Threadin g.Thread.Curren tThread.Current Culture = 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
"DigitGroup ing" property in CultureInfo or NumberFormatInf o.

Hope this helps
Jay
"G.Ashok" <gw******@hotma il.com> wrote in message
news:eI******** ******@TK2MSFTN GP11.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********@san charnet.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********@san charnet.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.EventArg s)

Me.MyCultureInf o.NumberFormat. CurrencyGroupSi zes = New Integer() {3, 2}
Threading.Threa d.CurrentThread .CurrentCulture = Me.MyCultureInf o

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

If Not IsNumeric(Me.Te xtBox1.Text) Then
Me.TextBox1.Tex t = "0"
End If

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("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.EventArg s) Handles TextBox1.Leave

If Not IsNumeric(Me.Te xtBox1.Text) Then
Me.TextBox1.Tex t = "0"
End If

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("'Rs.'#,##0.0 0
CR;'Rs.'#,##0.0 0 DB;Zero")

End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)

Me.MyCultureInf o.NumberFormat. CurrencyGroupSi zes = New Integer() {3,
2}
Threading.Threa d.CurrentThread .CurrentCulture = Me.MyCultureInf o

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 (CurrencyGroupS izes = New Integer() {3, 2}) and
passing in the parameter of the ToString() like this.

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("'Rs.'#,##0.0 0
CR;'Rs.'#,##0.0 0 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*******@usin ternet.com> wrote in message
news:eb******** ******@tk2msftn gp13.phx.gbl...

"Rajesh Nandwani" <tr********@san charnet.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.EventArg s)

Me.MyCultureInf o.NumberFormat. CurrencyGroupSi zes = New Integer()

{3, 2} Threading.Threa d.CurrentThread .CurrentCulture = Me.MyCultureInf o

End Sub
Private Sub TextBox1_Leave( ByVal sender As Object, ByVal e As System.EventArg s) Handles TextBox1.Leave
If Not IsNumeric(Me.Te xtBox1.Text) Then
Me.TextBox1.Tex t = "0"
End If

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("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********@san charnet.in> wrote in message
news:OT******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP15.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
"DigitGroup ing" property in CultureInfo or NumberFormatInf o.

Hope this helps
Jay
"G.Ashok" <gw******@hotma il.com> wrote in message
news:eI******** ******@TK2MSFTN GP11.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.EventArg s) Handles TextBox1.Leave

If Not IsNumeric(Me.Te xtBox1.Text) Then
Me.TextBox1.Tex t = "0"
End If

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("'Rs.'#,##0.0 0
CR;'Rs.'#,##0.0 0 DB;Zero")

End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)

Me.MyCultureInf o.NumberFormat. CurrencyGroupSi zes = New Integer()
{3,2}
Threading.Threa d.CurrentThread .CurrentCulture = Me.MyCultureInf o

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 (CurrencyGroupS izes = New Integer() {3, 2}) and
passing in the parameter of the ToString() like this.

Me.TextBox1.Tex t = CDec(Me.TextBox 1.Text).ToStrin g("'Rs.'#,##0.0 0
CR;'Rs.'#,##0.0 0 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******** ******@tk2msftn gp13.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********@san charnet.in> wrote in message
news:OT******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP15.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
"DigitGroup ing" property in CultureInfo or NumberFormatInf o.

Hope this helps
Jay
"G.Ashok" <gw******@hotma il.com> wrote in message
news:eI******** ******@TK2MSFTN GP11.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
3921
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 123.0000 123 i.e. I want to trim trailing zeros and (decimal point if no decimal values
1
1418
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 int.Parse(summaryObjectArray.ToString()).ToString("N",cultureInfo) how can i assign less/more decimal digits to a number i have 1'000'000.00 //standard format i...
2
3126
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 want 2). Soooo ... I tried to create the cultureinfo object, set the format decimal digits, then assign that to formatinfo on the column. Anyone see...
8
6134
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); tbxDisplayResult.Text = DateTime.Parse(tbxInputArea.Text, culture).ToString("yyyy MMMMMMMMMM dd");
14
4291
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 unformatted data values (as decimals) just fine, so I know there's not a problem with the data retrieval, just the formatting. I have read that this...
4
4403
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 trouble when I need to parse the sql server decimal as an asp.net double! For example:
8
15036
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 independent from the culture of the current user, I use decimal.Parse(volume, new System.Globalization.CultureInfo("fr-FR", true)); but this...
9
3227
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
6540
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 lingo) So you should use something like ToString("N") If you are sure you want 2 digits after decimal separator, then use "N2" --
0
7832
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7747
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6498
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.