473,698 Members | 2,306 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 9168

"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
3935
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
1420
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 think..
2
3130
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 where I went astray? Dim USCultureInfo As CultureInfo = New CultureInfo("en-us")
8
6140
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
4332
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 would work: lblPrice.Text = prodRow.ToString("C");
4
4410
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
15054
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 function fails with : Exception : Input string was not in a correct format.
9
3259
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
6545
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
8668
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8598
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.