Solved

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

Posted on 2014-02-18
9
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 143

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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