Sponsored Content
Full Discussion: Help on Modulus
Top Forums UNIX for Dummies Questions & Answers Help on Modulus Post 302524228 by Ariean on Sunday 22nd of May 2011 12:26:32 PM
Old 05-22-2011
Help on Modulus

Hello All,
I am trying to do a simple calculation using modulus (%) as shown below. But some how it is not showing me correct result. It says "0.166667" is equal to "0" which is wrong. Could you please help me how can i make it work. Thanks a lot.

Code:
#!/bin/ksh
attempt_count=10
SLEEP=60
poll_time=`nawk 'BEGIN { print ('${attempt_count}'*'${SLEEP}')/3600 }'`

echo "poll time" $poll_time
echo "mod time" $((poll_time%5))

if [ "$((poll_time%5))" = "0" ] ; then
        echo correct
else
        echo wrong
fi

Wrong Result:
Code:
poll time 0.166667
mod time 0
correct

Expected output as per Oracle sql statement:

Code:
select mod(0.166667,5) from dual

output:
  0.166667


Last edited by pludi; 05-22-2011 at 02:51 PM..
 

3 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help in modulus operator in Bash

Hi, I would like to know given that i have two columns and I would like to take the positive integer of the differences between the two columns. which means |3-2|=1; |2-3|=1 as well. I would like to know do Bash recognize | | as well for this purposes? Thanks. -Jason (2 Replies)
Discussion started by: ahjiefreak
2 Replies

2. Shell Programming and Scripting

Modulus operator

What is the modulus operator in korn shell?? (5 Replies)
Discussion started by: manash.paul
5 Replies

3. Shell Programming and Scripting

awk Division and modulus

I need to read the file divide 3 column with 2nd and run a modulus of 10 and check whether the remainder is zero or not if not print the entire line. cat filename | awk '{ if ($3 / $2 % 10 != 0) print $0}' Whats wrong with it ? (4 Replies)
Discussion started by: dinjo_jo
4 Replies
All times are GMT -4. The time now is 01:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy