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 Belfortbucks, Today, 09:29 PM
                0 responses
                6 views
                0 likes
                Last Post Belfortbucks  
                Started by zstheorist, Today, 07:52 PM
                0 responses
                7 views
                0 likes
                Last Post zstheorist  
                Started by pmachiraju, 11-01-2023, 04:46 AM
                8 responses
                151 views
                0 likes
                Last Post rehmans
                by rehmans
                 
                Started by mattbsea, Today, 05:44 PM
                0 responses
                6 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                33 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Working...
                X