## Convert floating to integer in ksh

Convert floating to integer in ksh
# 1
04-22-2020
Convert floating to integer in ksh

I am having a floating variable which may or may not be float, but the output must be in interger only.

Suppose the variable "a" has float value, then it should be convert to nearest interger value. For example : 23.4 should be convert to 23 and 27.86 should be convert to 28.

So i tried th below code and and the error.

CODE

ERROR

Last edited by looty; 04-22-2020 at 12:18 AM..
 looty View Public Profile for looty Find all posts by looty
# 2
04-22-2020
Maybe try something basic like this in ksh?

 Neo View Public Profile for Neo Visit Neo's homepage! Find all posts by Neo
# 3
04-22-2020
... that works in ksh93 and newer.

ksh88 needs
# 4
04-22-2020
The problem is it rounds both down and up; and int() function rounds down only...
EDIT:
Apologies; ignore, I misread the OP's requirements...

Last edited by wisecracker; 04-22-2020 at 02:01 PM.. Reason: see EDIT:
 wisecracker View Public Profile for wisecracker Find all posts by wisecracker

## Convert floating point to a number

Hello Guys, I have a floating point number 1.14475E+15 I want to convert this number in to full number (Integer or Big integer). I tried couple of functions it did not work. When I use INT=\${FLOAT/.*} I am getting value as 1. I don't want a truncated value #!/bin/bash #...

## Changing integer columns to floating decimal columns

I have a document that has 7 columns. eg. \$1 \$2 \$3 \$4 \$5 \$6 \$7 string string string string integer integer integer The 6th and 7th columns are a mix of integers and floating decimals (with 4 decimal places). I need to convert the last 2 columns so that all...

## [Solved] need to convert decimal to integer

Using below command awk 'NR==FNR{A=\$1;next} {sum+=(\$2*A)}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt answer:351770174.00000 how to convert this to 351770174. when i try with below command i am getting different result. awk 'NR==FNR{A=\$1;next}...

## How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this remaining=\$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print...

## Convert to Integer

Hi fellows!! i'm doing something which is not working out for me properly which i don't understand why nowdate=`date +%s` echo \$nowdate now the problem how to convert a date which is stored in a variable mydate="22/Oct/2011" mydate=`date -d '\$mydate' +%s` it gives error...

## Increment a floating number in ksh

Hi ! How to increment a varibale in ksh. #!/bin/ksh set -x RELEASE_NUM=5.2.103 VAL=0.0.1 RELEASE_NUM=`echo \$RELEASE_NUM + \$VAL | bc` echo \$RELEASE_NUM The above code is throwing this error. + RELEASE_NUM=5.2.103

## Floating point to integer in variable length lines

Hi ! I'm looking for a way to transform certain floating point numbers in a one-line, variable length file to integers. I can do this in a crude way with sed : sed -e 's/0\.\(\):/\1:/g' -e 's/0\.0\(\):/\1:/g' -e 's/1\.000:/100:/g' myfile ... but this doesn't handle the rounding correctly. ...

## Check if input is an integer or a floating point?

Hiii I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ? Thanking you

## Replace floating-point by integer in awk

Hi, I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format... Geometry "geometry" -> "geometry" 1 Pd 46.0000 -0.19290971 0.00535260 0.02297606 2 P ...

## convert from an integer to a string

i want to convert from an integer to a string..in unix...i am writing a C program with embedded SQL... I remeber using itoa...but for some reason it doesnt work......i cant find it in the manual..... Maybe that is the wrong command..... but i have checked Dev Studio.....and it doest exist in the...