Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

double printed like an integer

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

    double printed like an integer

    Hi again, almost finishing this indicator

    Look at this code:
    double mydouble;
    mydouble=5/3;
    Print(mydouble);
    mydouble=5.3/3.3;
    Print(mydouble);

    results:
    1
    1,66666666666667

    question:
    How can i obtain the last result making the division between two integers (5/3)?
    I hope not to declare
    double mydouble=0.0;
    because i'm really speaking about a matrix:
    private double [] mydouble = new double[10000];
    and I don't know how to initialize it (i expect not with a for or while for each element)

    thanks,
    jr.

    #2
    excuse me:
    not 5.3/3.3

    i meant:
    5.0/3.0

    Comment


      #3
      Hi jr,

      Math.Floor returns the integer part of a double:
      Math.Floor(5.0/3.0) -> 1.0

      Regards
      Ralph

      Comment


        #4
        I'm afraid I didn't explain correctly.
        What I need is:
        5/3 -> 1,66666666666667

        5 -> integer
        3 -> integer
        result -> double

        thank you so much,
        jr.

        Comment


          #5
          I didn't read your post correctly. You have to convert at least one variable to double prior to application, there is no other way around:

          double dblVal = 5;
          int intVal = 3;
          double mydouble = dblVal / intVal;

          I expect 1.6666 as the result.
          You could give it a try, I didn't test it.

          Regards
          Ralph

          Comment


            #6
            You're right, but I can't define the variables like double (I should change many lines). Isn't there any conversion, something like math.todouble(int) or something like that?

            Comment


              #7
              Still not sure, how you do apply the integers troughout your code. You could convert integers before usage with a type cast:

              int int5= 5;
              int int3 =3;
              double mydouble = (double)int5 / int3;

              Regards
              Ralph

              Comment


                #8
                Fixed. I was mistaken. I could change the variables affected. Only nine. I declared them double and works ok.

                thank you so much
                jr.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                59 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Today, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Started by olisav57, Today, 07:39 PM
                0 responses
                7 views
                0 likes
                Last Post olisav57  
                Started by trilliantrader, Today, 03:01 PM
                2 responses
                21 views
                0 likes
                Last Post helpwanted  
                Started by cre8able, Today, 07:24 PM
                0 responses
                10 views
                0 likes
                Last Post cre8able  
                Working...
                X