Sponsored Content
Top Forums Shell Programming and Scripting Is there a simpler way to validate user input for float? Post 302487709 by ygemici on Thursday 13th of January 2011 09:39:59 AM
Old 01-13-2011
Code:
# x="sed '/[0-9][0-9]*\.*[0-9]*/s/\(.*\)\.\(.\)$/\1.\20/;/^[0-9][0-9]*$/s/\(.*\)/\1.00/'"

Code:
# a=12 ; echo $a|eval $x
12.00
# a=12.1 ; echo $a|eval $x
12.10


Last edited by ygemici; 01-13-2011 at 11:32 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

How to validate input values

Hi How would i validate value of a variable whether it is number,date or string Thanks in advance Sas (5 Replies)
Discussion started by: SasDutta
5 Replies

3. Shell Programming and Scripting

validate input

the user inputs names that have to be inside square brackets I want to check if the user puts the brackets and if not ask him to re-enter the names (9 Replies)
Discussion started by: DDoS
9 Replies

4. UNIX for Dummies Questions & Answers

input a float data and add them in shell in linux

I want to input a float data and add them in shell in linux. I am new user of it can anyone tell me how I can do it? thanx (5 Replies)
Discussion started by: purva
5 Replies

5. Shell Programming and Scripting

float input

how to input float data type in bash shell programming in linux? I am new to it so unaware to use the commands plz help me out. thank you. (6 Replies)
Discussion started by: purva
6 Replies

6. UNIX for Dummies Questions & Answers

BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg: read answer case $answer in *) echo "OK" ;; *) echo "This is a number" read answer ;; *) echo... (2 Replies)
Discussion started by: 602chrislys
2 Replies

7. Shell Programming and Scripting

How to validate input parameters?

Hi, I wonder how I can know if the input parameters to the script are numbers or text Thanks (11 Replies)
Discussion started by: Gengis-Kahn
11 Replies

8. Shell Programming and Scripting

Another validate input Question.

I'm writing a bash shell script to 'help' me post to susepaste (I can NEVER remember the time options). Here's the code: #!/bin/bash ########## # # Project : personal script. # Started : Wed Aug 03, 2011 # Author : Habitual # Description : susepaste c-li script with user... (5 Replies)
Discussion started by: Habitual
5 Replies

9. Shell Programming and Scripting

[bash] how is proper way to validate user input

hi all, i have a script that need user input provide all variables that needed to complete a job. this is my current script: echo "type file source and it full path :" read INPUTFILE if || ; then echo "ERROR: you didn't enter a file source or file source is not... (2 Replies)
Discussion started by: makan
2 Replies

10. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies
BINDEC(3)								 1								 BINDEC(3)

bindec - Binary to decimal

SYNOPSIS
number bindec (string $binary_string) DESCRIPTION
Returns the decimal equivalent of the binary number represented by the $binary_string argument. bindec(3) converts a binary number to an integer or, if needed for size reasons, float. bindec(3) interprets all $binary_string values as unsigned integers. This is because bindec(3) sees the most significant bit as another order of magnitude rather than as the sign bit. PARAMETERS
o $binary_string - The binary string to convert Warning The parameter must be a string. Using other data types will produce unexpected results. RETURN VALUES
The decimal value of $binary_string EXAMPLES
Example #1 bindec(3) example <?php echo bindec('110011') . " "; echo bindec('000110011') . " "; echo bindec('111'); ?> The above example will output: 51 51 7 Example #2 bindec(3) interprets input as unsigned integers <?php /* * The lesson from this example is in the output * rather than the PHP code itself. */ $magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2); p($magnitude_lower - 1); p($magnitude_lower, 'See the rollover? Watch it next time around...'); p(PHP_INT_MAX, 'PHP_INT_MAX'); p(~PHP_INT_MAX, 'interpreted to be one more than PHP_INT_MAX'); if (PHP_INT_SIZE == 4) { $note = 'interpreted to be the largest unsigned integer'; } else { $note = 'interpreted to be the largest unsigned integer (18446744073709551615) but skewed by float precision'; } p(-1, $note); function p($input, $note = '') { echo "input: $input "; $format = '%0' . (PHP_INT_SIZE * 8) . 'b'; $bin = sprintf($format, $input); echo "binary: $bin "; ini_set('precision', 20); // For readability on 64 bit boxes. $dec = bindec($bin); echo 'bindec(): ' . $dec . " "; if ($note) { echo "NOTE: $note "; } echo " "; } ?> Output of the above example on 32 bit machines: input: 1073741823 binary: 00111111111111111111111111111111 bindec(): 1073741823 input: 1073741824 binary: 01000000000000000000000000000000 bindec(): 1073741824 NOTE: See the rollover? Watch it next time around... input: 2147483647 binary: 01111111111111111111111111111111 bindec(): 2147483647 NOTE: PHP_INT_MAX input: -2147483648 binary: 10000000000000000000000000000000 bindec(): 2147483648 NOTE: interpreted to be one more than PHP_INT_MAX input: -1 binary: 11111111111111111111111111111111 bindec(): 4294967295 NOTE: interpreted to be the largest unsigned integer Output of the above example on 64 bit machines: input: 4611686018427387903 binary: 0011111111111111111111111111111111111111111111111111111111111111 bindec(): 4611686018427387903 input: 4611686018427387904 binary: 0100000000000000000000000000000000000000000000000000000000000000 bindec(): 4611686018427387904 NOTE: See the rollover? Watch it next time around... input: 9223372036854775807 binary: 0111111111111111111111111111111111111111111111111111111111111111 bindec(): 9223372036854775807 NOTE: PHP_INT_MAX input: -9223372036854775808 binary: 1000000000000000000000000000000000000000000000000000000000000000 bindec(): 9223372036854775808 NOTE: interpreted to be one more than PHP_INT_MAX input: -1 binary: 1111111111111111111111111111111111111111111111111111111111111111 bindec(): 18446744073709551616 NOTE: interpreted to be the largest unsigned integer (18446744073709551615) but skewed by float precision NOTES
Note The function can convert numbers that are too large to fit into the platforms integer type, larger values are returned as float in that case. SEE ALSO
decbin(3), octdec(3), hexdec(3), base_convert(3). PHP Documentation Group BINDEC(3)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy