472,958 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Format decimal thousands

Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(String.Format("{0:0,0.000}", test));

i can not obtain a decimal value with thousands separators (but without
Decimal.Parse do).

How can i solve?

Thanks in advance
--
Luigi

Sep 15 '08 #1
3 4655
Can you clarify what you are trying to do? A decimal is just a number -
it never really contains any separators. The string version might, but
you've already demonstrated that with your String.Format and Parse usage.

Marc
Sep 15 '08 #2
On Sep 15, 2:15*pm, Luigi <ciupazNoSpamGra...@inwind.itwrote:
Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(String.Format("{0:0,0.000}", test));
As you have multiple possible decimal separators [BOTH comma AND DOT
are used in different locales] in your string, you will have to use
the Parse function specifying which particular format applies...
>
i *can not obtain a decimal value with thousands separators (but without
Decimal.Parse do).

How can i solve?

Thanks in advance
--
Luigi
Sep 15 '08 #3
I don't see why... both the Format and Parse will take the culture into
account. In the format string the . and , are palceholders for the
decimal and thousand separators (they aren't used verbatim). So this
code should work "as is":

static decimal? TestRoundtrip()
{
decimal? test = 1200345.56m;
string s = String.Format("{0:0,0.000}", test);
decimal? test2 = Decimal.Parse(s);
Console.WriteLine(test2);
return test2;
}
static void Main()
{
decimal? a, b;
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("fr-FR");
a=TestRoundtrip();
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("en-GB");
b=TestRoundtrip();
Console.WriteLine(a==b); // returns true
}
Sep 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
2
by: Wilfried Mestdagh | last post by:
Hi, I have something like this: string S = dblN.ToString("F4") and S contain the decimal point as in the windows setting (currently ',' on this machine). But I want it to be let's say: '.'...
1
by: nic | last post by:
Hi, I have a textbox value that I need to force (and format) to be a numeric value. For example, I want to allow a user to type 1000 or 1,000 or 1,000,000 but not something that is not numberic....
5
by: Edward Hartfield | last post by:
I'm am relatively new to Python but use it daily. Today, I went looking for a function, like PHP's number_function, that will take a number and return a string with number formatted with grouped...
3
by: Ntl News Group | last post by:
I have a text box that contains the number 1234, I want the value form the text box to display in a second text box so I used: = The problems is that this displays 1234 and I want it to display...
4
by: toffee | last post by:
Hi all, I created a little button which when clicked will run a query on mysql db and output the results as an excel spreadsheet. I do this by setting the header as application excel. All works...
2
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I know how to format a string to use decimal places: Code: Console.WriteLine(string.Format("$ {0:0.00}", 4)); Output: $ 4.00 How would I format a string to use the Thousands Separator? ...
2
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, having a decimal value, like this: decimal? valueTest = 1234567.8999 how can I format it so it appears with thousands separator and 2 decimal digits? Like: 1,234,567.90
2
by: paolo | last post by:
Thanks in advance to everyone that will give me help for these questions. The function formatCurrency is used to auto-format a numeric value with thousands separators and a decimal separator. ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.