Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fcvt(3) [redhat man page]

ECVT(3) 						     Linux Programmer's Manual							   ECVT(3)

NAME
ecvt, fcvt - convert a floating-point number to a string. SYNOPSIS
#include <stdlib.h> char *ecvt(double number, int ndigits, int *decpt, int *sign); char *fcvt(double number, int ndigits, int *decpt, int *sign); DESCRIPTION
The ecvt() function converts number to a null-terminated string of ndigits digits (where ndigits is reduced to an system-specific limit determined by the precision of a double), and returns a pointer to the string. The high-order digit is nonzero, unless number is zero. The low order digit is rounded. The string itself does not contain a decimal point; however, the position of the decimal point relative to the start of the string is stored in *decpt. A negative value for *decpt means that the decimal point is to the left of the start of the string. If the sign of number is negative, *sign is set to a non-zero value, otherwise it's set to 0. If number is zero, it is unspecified whether *decpt is 0 or 1. The fcvt() function is identical to ecvt(), except that ndigits specifies the number of digits after the decimal point. RETURN VALUE
Both the ecvt() and fcvt() functions return a pointer to a static string containing the ASCII representation of number. The static string is overwritten by each call to ecvt() or fcvt(). NOTES
These functions are obsolete. Instead, sprintf() is recommended. Linux libc4 and libc5 specified the type of ndigits as size_t. Not all locales use a point as the radix character (`decimal point'). CONFORMING TO
SysVR2, XPG2 SEE ALSO
ecvt_r(3), gcvt(3), qecvt(3), setlocale(3), sprintf(3) 1999-06-25 ECVT(3)

Check Out this Related Man Page

ECVT(3) 						     Linux Programmer's Manual							   ECVT(3)

NAME
ecvt, fcvt - convert a floating-point number to a string. SYNOPSIS
#include <stdlib.h> char *ecvt(double number, int ndigits, int *decpt, int *sign); char *fcvt(double number, int ndigits, int *decpt, int *sign); DESCRIPTION
The ecvt() function converts number to a null-terminated string of ndigits digits (where ndigits is reduced to an system-specific limit determined by the precision of a double), and returns a pointer to the string. The high-order digit is nonzero, unless number is zero. The low order digit is rounded. The string itself does not contain a decimal point; however, the position of the decimal point relative to the start of the string is stored in *decpt. A negative value for *decpt means that the decimal point is to the left of the start of the string. If the sign of number is negative, *sign is set to a non-zero value, otherwise it's set to 0. If number is zero, it is unspecified whether *decpt is 0 or 1. The fcvt() function is identical to ecvt(), except that ndigits specifies the number of digits after the decimal point. RETURN VALUE
Both the ecvt() and fcvt() functions return a pointer to a static string containing the ASCII representation of number. The static string is overwritten by each call to ecvt() or fcvt(). NOTES
These functions are obsolete. Instead, sprintf() is recommended. Linux libc4 and libc5 specified the type of ndigits as size_t. Not all locales use a point as the radix character (`decimal point'). CONFORMING TO
SysVR2, XPG2 SEE ALSO
ecvt_r(3), gcvt(3), qecvt(3), setlocale(3), sprintf(3) 1999-06-25 ECVT(3)
Man Page

6 More Discussions You Might Find Interesting

1. Programming

need help on some converting command

Hi all, i am trying to use C in unix platform to convert a double variable (floating point) to a string variable. i tried using sprintf, ecvt, fcvt,gcvt. but all gave me funny output or altered the content. does anyone know how to convert the data and keep the original content. for... (3 Replies)
Discussion started by: szeliat
3 Replies

2. Shell Programming and Scripting

change 43% to 43.5

I have a column in % and I want to display it as a one decimal place number for sorting - what function would I be looking at for dropping the % sign? (2 Replies)
Discussion started by: nortypig
2 Replies

3. Shell Programming and Scripting

Converting string to negative decimal value

I need code for converting a string to a negative decimal value. For ex, i have the value in the form of a string (5489.95-) i need to convert it into decimal value (-5489.95) while getting output using printf command. i know how to get as a string a="5489.95-" printf "%10s"$a >>xyz.dat ... (5 Replies)
Discussion started by: angie1234
5 Replies

4. Shell Programming and Scripting

Print a number up to last significant digit after decimal point

I want to write/print a number through a shell script up to its last significant digit (LSD) after the decimal point. Say, x=10.00056000000000000 I want to print x as x=10.00056. Note that x can be any thing so I cannot know the position of the LSD always. Thanks. (16 Replies)
Discussion started by: hbar
16 Replies

5. Shell Programming and Scripting

Sum in terabyte

Hello, can someone help me in this I have a file of sizes in kilobyte I want to caculte the sum in terabyte using awk I would like to have one digit after the decimal point ( 2.8 TB for example) cat file 2881301319 3061567196 3010347398 3029693706 2906516319 2444536488... (2 Replies)
Discussion started by: Sara_84
2 Replies

6. Shell Programming and Scripting

Using awk to place decimal points at proper position

Hi, I have one input file which is delimited by pipe. I want to put decimal points in this input file at particular position in particular column and also get the negative sign (if any) at start of that column. $ cat Input_file.txt 11|10102693|1|20151202|10263204|20151127|N|0001... (7 Replies)
Discussion started by: Prathmesh
7 Replies