Translate

Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Beginning Google Maps API 3
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of Android Wireless Application Development

Convert Integer to Float in Korn Shell

There is no explicit mechanism, such as float(integer), in the Korn Shell (ksh93) to convert an integer to a float which in the Korn Shell is by default a long double. By default, dividing integer 1 by 3 produces 0: $ integer x=1 $ echo $(( x/3 )) 0 $ So how to you get the result, 0.3333 …, which you probably were expecting? You can convert x to floating point and then do the division by replacing the 3 with either 3. or, as I normally do, with 3.0: $ integer x=1 $ echo $(( x/3. )) 0.333333333333333333 $