Sponsored Content
Top Forums Programming Double to const char conversion Post 302769856 by DGPickett on Wednesday 13th of February 2013 04:58:43 PM
Old 02-13-2013
Man Page for fcvt (opensolaris Section 3c) - The UNIX and Linux Forums says The high-order digit is non-zero, unless the value is 0. The
low-order digit is rounded. The position of the radix character rela-
tive to the beginning of the string is stored in the integer pointed to
by decpt (negative means to the left of the returned digits).

Maybe you want to convert with one of the options of sprintf: https://www.unix.com/man-page/opensolaris/3/sprintf/
Code:
$ printf '%8.6f\n' .00123456
0.001235
$

Or use decpt to figure how much of "0.0*" to tack onto the front.
Code:
sprintf( fps2, "%.*s%s", 10 + dec, "0.00000000", fps );

This User Gave Thanks to DGPickett For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

char to int64 conversion

Hi, I'm converting a C program that I made using the Visual Studio. I now use GCC (over Linux) and can't find some equivalences. I changed my __int64 definitions to unsigned long long, but can't find an equivalent to the microsoft i64toa() function, which let you convert a char* to a 64 bit... (1 Reply)
Discussion started by: Raspoutine
1 Replies

2. Programming

diff b/w char const in C/C++

hi, what is the difference b/w char in C and C++.and give me the examples. Thanks... sarwan (3 Replies)
Discussion started by: sarwan
3 Replies

3. UNIX for Dummies Questions & Answers

int open(const char *pathname, int flags, mode_t mode) doubt...

hello everybody! I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(){ int fileDescriptor; fileDescriptor =... (2 Replies)
Discussion started by: csnmgeek
2 Replies

4. UNIX for Dummies Questions & Answers

ANSI C, char to hex conversion

Hi, I have a char buf,ch; and the buf is filled with the result from MySQL server which I get like this numbytes = recv(sock, buf, 1024, 0));I have the followingcode to display the results printf("received %ld bytes:\n",numbytes); for(c=0;c<numbytes;c++){ ch = (char)buf; ... (2 Replies)
Discussion started by: alikims
2 Replies

5. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

6. Programming

conversion to 'char' from 'int' warning

Hi, I wrote a simple code in C++ converting from UpperToLower case characters. However, my compiler gives me a warning: "warning: conversion to 'char' from 'int' may alter its value". Any tips? I would like to stress, I don't want to load my string into char array. int ToLower(string... (4 Replies)
Discussion started by: kajolo
4 Replies

7. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

8. Programming

Using const char*

I am writing some code in C++ to print a message using fprintf Here is an example void pr_desc( FILE* stream, int shift, const char* desc) { const char* format="%*s\e; fprintf(stream,format,shift,"",desc); } I call it using const char* desc; ... (4 Replies)
Discussion started by: kristinu
4 Replies

9. Programming

Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program. Here is the code #include <stdio.h> #include <stdlib.h> #include <string.h> #define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n" #define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies

10. Programming

Bool vs char * conversion

I have a problem at make step to install a downloaded package consisted of different programs. In file included from kcdbext.cc:16:0: kcdbext.h: In member function �char* kyotocabinet::IndexDB::get(const char*, size_t, size_t*)’: kcdbext.h:1281:14: error: cannot convert �bool’ to... (3 Replies)
Discussion started by: yifangt
3 Replies
ecvt(3C)						   Standard C Library Functions 						  ecvt(3C)

NAME
ecvt, fcvt, gcvt - convert floating-point number to string SYNOPSIS
#include <stdlib.h> char *ecvt(double value, int ndigit, int *restrict decpt, int *restrict sign); char *fcvt(double value, int ndigit, int *restrict decpt, int *restrict sign); char *gcvt(double value, int ndigit, char *buf); DESCRIPTION
The ecvt(), fcvt() and gcvt() functions convert floating-point numbers to null-terminated strings. ecvt() The ecvt() function converts value to a null-terminated string of ndigit digits (where ndigit is reduced to an unspecified limit determined by the precision of a double) and returns a pointer to the string. The high-order digit is non-zero, unless the value is 0. The low-order digit is rounded. The position of the radix character relative to the beginning of the string is stored in the integer pointed to by decpt (negative means to the left of the returned digits). The radix character is not included in the returned string. If the sign of the result is negative, the integer pointed to by sign is non-zero, otherwise it is 0. If the converted value is out of range or is not representable, the contents of the returned string are unspecified. fcvt() The fcvt() function is identical to ecvt() except that ndigit specifies the number of digits desired after the radix point. The total num- ber of digits in the result string is restricted to an unspecified limit as determined by the precision of a double. gcvt() The gcvt() function converts value to a null-terminated string (similar to that of the %g format of printf(3C)) in the array pointed to by buf and returns buf. It produces ndigit significant digits (limited to an unspecified value determined by the precision of a double) in %f if possible, or %e (scientific notation) otherwise. A minus sign is included in the returned string if value is less than 0. A radix character is included in the returned string if value is not a whole number. Trailing zeros are suppressed where value is not a whole num- ber. The radix character is determined by the current locale. If setlocale(3C) has not been called successfully, the default locale, POSIX, is used. The default locale specifies a period (.) as the radix character. The LC_NUMERIC category determines the value of the radix character within the current locale. RETURN VALUES
The ecvt() and fcvt() functions return a pointer to a null-terminated string of digits. The gcvt() function returns buf. ERRORS
No errors are defined. USAGE
The return values from ecvt() and fcvt() might point to thread-specific data that can be overwritten by subsequent calls to these functions by the same thread. For portability to implementations conforming to earlier versions of Solaris, sprintf(3C) is preferred over this function. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
printf(3C), setlocale(3C), sprintf(3C), attributes(5), standards(5) SunOS 5.11 18 May 2004 ecvt(3C)
All times are GMT -4. The time now is 09:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy