Solved

Declare a double and show it like 1,0 instead of 1.0.

Posted on 2014-02-18
9
236 Views
Last Modified: 2014-02-18
Hi,

I want to display  the numbers 1.0 and 40.0 as 1,0 and 40,0 because we use the comma instead of the period. So I have put the numbers in a double value. But after testing the code it displayes: 1 instead of 1,0
 
      private void edtVal_InvalidValue(object sender, DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs e)
        {
          double Val1 = 1.0;
          double Val2 = 40.0;
            e.ExceptionMode = ExceptionMode.NoAction;
            switch (errType)
            {
                case ErrorType.MOLL:
                    XtraMessageBox.Show("The value must be between " + Val1  + " and " + Val2  "Error");
                    break;
                case ErrorType.MGDL:
                    XtraMessageBox.Show("The value must be between " + 18 + " and " + 720, "Error");
                    break;
                case ErrorType.KG:
                    XtraMessageBox.Show("The value cannot be higher then 400", "Error");
                    break;
                case ErrorType.LBS:
                    XtraMessageBox.Show("The value cannot be higher then 882", "Error");
                    break;
            }
        }

Open in new window


Peter
0
Comment
Question by:peterkiers
  • 5
  • 3
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39867240
to "format" a double to a string message exactly as you need it, you need to do so explicitly:
http://msdn.microsoft.com/en-us/library/kfsatb94%28v=vs.110%29.aspx
0
 
LVL 40
ID: 39867880
Val1.ToString("###.0",new System.Globalization.CultureInfo("fr"))

Open in new window

This forces the display of the decimal part even if it is 0, but using the decimal separator of the French language, which is the coma.

Add more # if you think that you might have values higher than 999.

This being said, I would do that only for stuff that does not display on the screen, such as files that require the coma or reports.

On the screen, you normally never specify a CultureInfo. Your role as a programmer is to follow the Control Panel.

The reason for that is that ToString without a specific culture follows the culture defined in the Control Panel, as do most numeric and date methods in the framework. If you display a coma as a decimal separator on a computer where the language is defined as English, there will be a conflict between what the user sees (the coma) and what he should usually type on that computer (the dot). You will end up with other problems later because the user will try to type a coma and the system won't accept it as a decimal separator.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39867946
I have this:

        {
            e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction;
            double val1 = 1.0;
            double val2 = 40.0;
            switch (errType)

            {
                case ErrorType.MOLL:
                    XtraMessageBox.Show("The value must be between " + val1.ToString() + " and " + val2.ToString(), "Error");

Open in new window


still show 1 and 40 in the message.

Peter
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:peterkiers
ID: 39867968
Val1.ToString("###.0",new System.Globalization.CultureInfo("fr"))

Do I have to specify a country. Is it possible to check the country specified in the pc.

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39868004
This doesn't work either:

  XtraMessageBox.Show("The value must be between " + val1.ToString("##.#", CultureInfo.CurrentCulture) + " and " + val2.ToString("##.#", CultureInfo.CurrentCulture), "Error");

Open in new window

0
 
LVL 40
ID: 39868032
If you really want a coma, do not specify the country, because you can end up with something else.

On my system for instance, since I am in the Montréal area, I have set my Control Panel to fr-CA for French Canadian. By default, this gives a coma as a decimal separator.

But because I am a programmer and am forced to used a dot in code, it annoys me to have to type a dot in my code and a coma in Excel, so I changed my decimal separator in the Control Panel to a dot even if everything else is fr-CA.

The problem, if I use fr-CA in my code, is that the Framework detects that my Control Panel is fr-CA, but with a dot as a decimal separator, so it adapts to what I have in the Control Panel and uses the dot with fr-CA, while it would normally give a coma.

Setting only for fr solves that problem. You end up with the default for standard French, which is the coma. And standard French cannot be changed through the Control Panel. So you are assured to get a coma.

If you want information about what is defined on the PC, use System.Globalization.CultureInfo.CurrentCulture. This provides you with properties for all the current settings defined in the Control Panel.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39868041
For your last post, use ##.0.

##.# does not force the 0, so when you do not have a decimal value, nothing prints. The 0 forces the output of at least one decimal, putting 0 if there is none.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39868048
Thanks, Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39868089
Ahh, I am happy it works great after testing it:

        private void edtVal_InvalidValue(object sender, DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs e)
        {
            e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction;
            double val1 = 1.0;
            double val2 = 40.0;
            switch (errType)
            {
                case ErrorType.MOLL:
                    XtraMessageBox.Show("The value must be between " + val1.ToString("##.0") + " and " + val2.ToString("##.0"), "Error");

Open in new window


Greetings,

Peter Kiers
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 47
Visual Studio 2013 and Eclipse Neon 6 37
No Data for DropDown List 2 25
MVC DDL Json Not Binding to Model 2 13
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question