473,663 Members | 2,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format decimal thousands

Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(S tring.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 4695
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 <ciupazNoSpamGr a...@inwind.itw rote:
Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(S tring.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.WriteLi ne(test2);
return test2;
}
static void Main()
{
decimal? a, b;
Thread.CurrentT hread.CurrentCu lture =
CultureInfo.Get CultureInfo("fr-FR");
a=TestRoundtrip ();
Thread.CurrentT hread.CurrentCu lture =
CultureInfo.Get CultureInfo("en-GB");
b=TestRoundtrip ();
Console.WriteLi ne(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
19225
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
2
6523
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: '.' always and independant the setting on the machine. Someone can explain the best (and fast) way to do this ?
1
3500
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. Essentially I want to ignore the commas. If I use the compareValidator it does not allow commas. Is there an easy way to do this? Also I need to format a string such as 1000 as 1,000 (without any decimal places) When I format 1000 as a...
5
14716
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 thousands and the decimal portion rounded to a given number of places. This is certainly needed when you want to take a floating-point value from a database and display it as currency, for instance. I could not find what I was looking for so I...
3
76483
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 1,234 using a comma for the thousands and no decimal places. I changed the format on the second text box to: =Format(,”Standard”)
4
2018
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 well except for a very strange problem. Let's say a column should say 16500.22. When I run it here from the uk, the cell will show 16500.22 When someone in Netherlands runs it, the cells shows 16,500,220,000 It looks like Excel is mixing the...
2
12298
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? for (int i = 0; i < 1000000; i++) // zero to one million
2
1533
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
2640
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. It works, but still has the following problems: °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Problem 1.
0
8436
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
8858
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
8771
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
8548
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
8634
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...
1
6186
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4182
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.