Shop OBEX P1 Docs P2 Docs Learn Events
PropC confusion - Page 3 — Parallax Forums

PropC confusion

13»

Comments

  • Beavis3215Beavis3215 Posts: 229
    edited 2017-01-02 18:53
    The 368 in theory is the time to run the code. In all practicality for what im doing it may not be needed.
  • Yes, I understand the purpose of the 368 offset. However, since you are getting -64 it appears that the offset should be 304 instead. I was just trying to explain why you are getting a value of -64.
  • Beavis3215Beavis3215 Posts: 229
    edited 2017-01-02 20:07
    No offense intended. I was just explaining what I thought was needed when I wrote it the code originally.
    Thanks for your help Dave
  • How do you implement getting the integer part of a decimal, and the fractional part of a decimal?
  • Beavis3215 wrote: »
    How do you implement getting the integer part of a decimal, and the fractional part of a decimal?

    I'm not sure if this is what you want, but here's one way using simpleide:
    
    
    #include "simpletools.h"                      // Include simple tools
    
    int main()                                    
    {
    int aninteger;                            
    float afloat1, adecpart;
    afloat1 = 27.4;               // separate this float into its int and dec parts
    aninteger = (int)afloat1;      
    adecpart = afloat1 - aninteger;
    
    print("%f,  %d,  %f \n", afloat1, aninteger, adecpart);
      
    }
    
    
    
    afloat1 is the float value to separate into its integer and decimal parts
    aninteger is the integer part
    adecpart is the decimal part (as a decimal). If you want to make it an integer you would have to multiply it by 10 to the number of places you want to have.

    One issue will be how the decimal value of a float is represented. For example 0.4 when multiplied by 1000 will print as 399. Converting 27.45 will result in 27, 0.45001, and if multiplied by 1000 will print the decimal part as 450.000763

    Tom
Sign In or Register to comment.