FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_ftoa.c
Go to the documentation of this file.
1
/* float to string, internal usage */
2
3
#include "
fb.h
"
4
5
char
*
fb_hFloat2Str
(
double
val,
char
*
buffer
,
int
digits,
int
mask )
6
{
7
ssize_t len, maxlen;
8
char
*
p
;
9
char
fmtstr[16], *fstr;
10
11
if
( mask &
FB_F2A_ADDBLANK
)
12
p = &buffer[1];
13
else
14
p =
buffer
;
15
16
switch
( digits )
17
{
18
case
7:
19
fstr = (
char
*)&
"%.7g"
;
20
break
;
21
case
16:
22
fstr = (
char
*)&
"%.16g"
;
23
break
;
24
default
:
25
sprintf( fmtstr,
"%%.%dg"
, digits );
26
fstr = &fmtstr[0];
27
}
28
29
maxlen = 1+digits+6+1;
30
31
len = snprintf( p, maxlen, fstr, val );
32
33
if
( len <= 0 || len >= maxlen )
34
{
35
buffer[0] =
'\0'
;
36
return
NULL
;
37
}
38
39
if
( len > 0 )
40
{
41
/* skip the dot at end if any */
42
if
( len > 0 )
43
if
( p[len-1] ==
'.'
)
44
p[len-1] =
'\0'
;
45
}
46
47
/* */
48
if
( (mask & FB_F2A_ADDBLANK) > 0 )
49
{
50
if
( p[0] !=
'-'
)
51
{
52
buffer[0] =
' '
;
53
return
&buffer[0];
54
}
55
else
56
return
p
;
57
}
58
else
59
return
p
;
60
}
rtlib
str_ftoa.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4