I have below awk
command which give mentioned result as well.
echo '1600000.00000000' '1600000.0000' | awk '{ print ($1 != $2) ? "true" : "false" }'
Result is : - false
As per numeric value the result given by the command is correct.
But I want command must consider both input('1600000.00000000'
'1600000.0000'
) as string
and give the result as true
. Because If you consider both input as string
then they are not equal difference is there in precision.
The awk command is a Linux tool and programming language that allows users to process and manipulate data and produce formatted reports. The tool supports various operations for advanced text processing and facilitates expressing complex data selections.
awk length(string) Function: The length() function calculates the length of a string. Explanation: Length of the string also includes spaces. 3. awk substr(s, p, n) Function: The length() function is used to extract substring function from a string.
From the GNU Awk user's guide, to force a number to be converted to a string, concatenate that number with the empty string ""
$ echo '1600000.00000000' '1600000.0000' |
awk '{ print ($1"" != $2"") ? "true" : "false" }'
You can also use sprintf
:
echo '1600000.00000000' '1600000.0000' |\
awk '{ print(sprintf("%f",$1) == sprintf("%f",$2)) ? "true": "false"}'
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With