Nelson Serafica <[EMAIL PROTECTED]> writes:

> I'm trying to create a script that will convert b/s to kb/s. To
> convert to kb/s, I must divide it to 1000 b/s. However, the answer
> does not contain the remainder. When I do "expr 5 / 3", it shows only
> 1 (suppose to be 1.6). Doesn't show the remainder .6.

Clarification (forgive my being pedantic): .6 is not the remainder of
the division -- it's the fractional part (i.e. 6/10).

The term "remainder" is the whole (integral) number "left over" (hence
remainder) from an integral division, such that

 a = (b * n) + r given a / n = b, remainder r [1]

so

 5 / 3 = 1 (remainder 2)

However, the solution i

>
> I search in Google and it says the "%" is remainder of a division. But
> when I do expr 5 % 3, it shows "2". It suppose to be 6, am I right?

No. '%' is the modulo operator, which does give the remainder of an
integer division; 5 % 3 is indeed 2. What you need is the fractional
component.

When representing fractional numbers (that is, numbers which have digits
after the decimal point), you use floats, or otherwise known as floating
point numbers. expr(1) doesn't deal with floating point division, so
you'll have to resort to bc(1).


[1] Actually, you can represent the above division with the following
    equation:

      a / n = b + (r / n)

    For instance, with the above values (a = 5, n = 3):

      5 / 3 = b + (r / 3)

    we can then substitute and follow the algebra:

      5 / 3 = 1 + (2 / 3)
            = 1 + (0.66~)
            = 1.6~

    And yes, I'm a math geek too.

-- 
JM Ibanez
Software Architect
Orange & Bronze Software Labs, Ltd. Co.

[EMAIL PROTECTED]
http://software.orangeandbronze.com/
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph

Reply via email to