Menu

Does GCB round or truncat

Help
MBB
2015-11-22
2015-11-23
  • MBB

    MBB - 2015-11-22

    When you divide two numbers in GCB and the result produces a number with a remainder does GCB round up, round down,or truncate the number?

    For example:

    100/7 = 14.2857. Does GCB give 14 or 15 as the answer?

    143 / 57 = 2.508. Do we get 2 or 3?

    If it is rounding, at what valuie does change from rounding down to rounding up?

     
  • Anobium

    Anobium - 2015-11-22

    Great Cow Basic uses integer maths. No rounding occurs. 100/7 = 14. Try this in the Windows calculator by selecting the Programmer calculator. The results are the same.

     
  • MBB

    MBB - 2015-11-22

    Thanks!

     
  • Anobium

    Anobium - 2015-11-23

    It is good to know the following. When completing a division the variable SysCalcTempX will contain the remainder of the division.

    Here is an example of using SysCalcTempX.

        If OutValueTemp > 0 Or SerPrintVal >= 10 Then
            OutValueTemp = SerPrintVal / 10       ' This is the division
            SerPrintVal = SysCalcTemp        ' Carry over integer.
            HSerSend(OutValueTemp + 48)
            Wait USART_DELAY
        End If
    

    Anobium

     

    Last edit: Anobium 2015-11-23

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.