• AVR Freaks

Hot!Math Calculation

Author
john_ive
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2017/05/22 22:22:08
  • Location: 0
  • Status: offline
2020/11/22 02:13:00 (permalink)
0

Math Calculation

To find the percentage value,I did an calculation in PIC16F886
 
percentage = (3% 15); Like this,I have tried.15 is total value and 3 is received,variable value.While trying this calculation I can't get any output.How to do percentage calculation in PIC16F886.?
#1

6 Replies Related Threads

    Hen
    Super Member
    • Total Posts : 115
    • Reward points : 0
    • Joined: 2018/10/24 04:01:44
    • Location: 0
    • Status: offline
    Re: Math Calculation 2020/11/22 03:35:38 (permalink)
    +1 (1)
    For lack of information, if were talking C the "%" represent modulus division.
    #2
    ric
    Super Member
    • Total Posts : 28967
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Math Calculation 2020/11/22 03:41:46 (permalink)
    +1 (1)
    john_ive
    To find the percentage value,I did an calculation in PIC16F886
     
    percentage = (3% 15); Like this,I have tried.15 is total value and 3 is received,variable value.While trying this calculation I can't get any output.How to do percentage calculation in PIC16F886.?

    I assume you don't actually have any C books to refer to.
    As Hen noted, the "%" operator is used for something else entirely in C.
    Why waste an operator, when 15% is simply "multiply by 15 and divide by 100."
    The best way to do that depends upon if you are using integer or float variables, but you have not revealed that detail.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    1and0
    Access is Denied
    • Total Posts : 11505
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Math Calculation 2020/11/22 05:55:42 (permalink)
    0
    john_ive
    To find the percentage value,I did an calculation in PIC16F886
     
    percentage = (3% 15); Like this,I have tried.15 is total value and 3 is received,variable value.While trying this calculation I can't get any output.How to do percentage calculation in PIC16F886.?

    To get 3% of 15, you will have to use floating point math. ;)
    float percentage = 15 * 0.03;

    ... or 15% of 3:
    float percentage = 3 * 0.15;

    post edited by 1and0 - 2020/11/22 06:05:24
    #4
    NorthGuy
    Super Member
    • Total Posts : 6405
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Math Calculation 2020/11/22 06:50:01 (permalink)
    +1 (1)
    15*3/100

     
    Also, make sure your variables are long enough.
    post edited by NorthGuy - 2020/11/22 06:51:16
    #5
    1and0
    Access is Denied
    • Total Posts : 11505
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Math Calculation 2020/11/22 07:05:42 (permalink)
    +2 (2)
    NorthGuy
    15*3/100


    = 0
    #6
    NorthGuy
    Super Member
    • Total Posts : 6405
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Math Calculation 2020/11/22 07:27:57 (permalink)
    +2 (2)
    1and0
    NorthGuy
    15*3/100


    = 0



    How the hell could I write this.
     
    3*100/15

    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5