• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with double variables

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with double variables

    Hello, I am trying to make a small change to an indicator I use.
    It uses a private double variable and when this variable is set to values above 1 like 1.9 it works as expected. But when I try to set a value of say 0.9, it resets later to 1, as if values bellow 1 were not accepted. This behaviour should not exist right?
    After all we re dealing with the correct type of variable.
    The solution I ve come up with is to set the variable double but with an integer value, then in calculations divide it by 1000. It works, but from a programmer perspective it just adds complexity thus calculations to the output of the formula. Makes no sense.

    private double aTRmultiplier = 786

    Am I doing something wrong or have I come across some kind or error?

    Thank you very much

    S C

    #2
    Originally posted by secaarco View Post
    Hello, I am trying to make a small change to an indicator I use.
    It uses a private double variable and when this variable is set to values above 1 like 1.9 it works as expected. But when I try to set a value of say 0.9, it resets later to 1, as if values bellow 1 were not accepted. This behaviour should not exist right?
    After all we re dealing with the correct type of variable.
    The solution I ve come up with is to set the variable double but with an integer value, then in calculations divide it by 1000. It works, but from a programmer perspective it just adds complexity thus calculations to the output of the formula. Makes no sense.

    private double aTRmultiplier = 786

    Am I doing something wrong or have I come across some kind or error?

    Thank you very much

    S C
    Hi S C

    I think this is the solution: open 'Properties' at the base of the script and change the first argument in Math.Max to 0 as below:

    Code:
    public double Name
            {
                get { return name; }
                set { name= Math.Max(0, value); }
            }
    It took me a long time to work this out myself when I first encountered the problem!

    Comment


      #3
      Regarding the proposed solution by Arbuthnot

      Arbuthnot, your solution worked flawlessly. It turned the variable behaviour as it was expected.
      I thank you very much for this little gem.

      Have a pleasant weekend, enjoy.

      Best, SC

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by [email protected], Yesterday, 07:45 AM
      1 response
      8 views
      0 likes
      Last Post koganam
      by koganam
       
      Started by tgn55, Today, 07:22 AM
      0 responses
      2 views
      0 likes
      Last Post tgn55
      by tgn55
       
      Started by U0000999, Today, 05:17 AM
      0 responses
      4 views
      0 likes
      Last Post U0000999  
      Started by Prataturry89, Today, 03:40 AM
      0 responses
      5 views
      0 likes
      Last Post Prataturry89  
      Started by UltraFastKetoBoost28, Today, 02:43 AM
      0 responses
      6 views
      0 likes
      Last Post UltraFastKetoBoost28  
      Working...
      X