Show us your code! You apparently are an expert on converting numbers into strings --- let us see your wonderful code! --- you are just telling lies again; you don't have any code...
This is my code from the novice-package:
-------------------------------------------------------------------------
\ ******
\ ****** The following is for numeric output.
\ ******
: comma ( d -- d )
[char] , hold ;
: dot ( d -- d )
[char] . hold ;
: _# ( d -- d_less_digit ) \ digit if number is non-zero, else a blank
2dup d0= if bl hold else # then ;
: _comma ( d -- d ) \ comma if number is non-zero, else a blank
2dup d0= if bl hold else comma then ;
\ _# and _comma are used to blank-out the leftmost of the number if the digits are zero.
: book-sign ( d neg? -- d )
if [char] - else [char] + then hold ;
\ This is a bookkeeping-style sign. It prints a + for positive rather than print nothing.
item ?sgn \ used by ?# and ?COMMA
: ?# ( d -- new-d ) \ needs ?SGN set \ similar to _# except puts a - in there if ?SGN is set
2dup d0= if
?sgn if ?sgn sign then
false to ?sgn
else
# then ;
: ?comma ( d -- d ) \ needs ?SGN set \ similar to _comma except puts a - in there if ?SGN is set
2dup d0= if
?sgn if ?sgn sign then
false to ?sgn
else
comma then ;
: <big.> ( d -- adr cnt ) \ used for big numbers that need commas for clarity
2dup d0< to ?sgn dabs
<#
# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?# ?# ?# ?comma
?#
#> ;
: big. ( d -- )
<big.> type ;
item ~#soft \ TRUE implies that ~# shouldn't output zeros
: ~# ( Da -- Db ) \ needs ~#SOFT set
~#soft if
2dup 10 um/mod drop if # false to ~#soft
else 1 10 m*/ then
else
# then ;
: ~. ( D -- D ) \ needs ~#SOFT set
~#soft not if [char] . hold then ;
\ ~# is used for the digits to the right of the decimal point.
\ ~. is used for the decimal point.
: round-off { prec -- } \ float: n -- new-n
prec 1 ?do 10.e f* loop fnear
prec 1 ?do 10.e f/ loop ;
: adjust-down ( adjustment -- new-adjustment ) \ float: n -- new-n
begin fdup 10.e f>= while
10.e f/ 1+ repeat ;
: adjust-up ( adjustment -- new-adjustment ) \ float: n -- new-n
begin fdup 1.e f< while
10.e f* 1- repeat ;
: exponent { prec | sgn -- adjustment } \ float: n -- new-n
0 \ -- adjustment
fdup f0= if exit then
fdup f0< to sgn fabs
adjust-up
adjust-down prec round-off adjust-down
sgn if fnegate then ;
: #exponent ( n -- ) \ must be called from within <# #>
?dup if
dup >r abs 0 \ -- d
#s r> sign [char] e hold \ -- d0
2drop then ;
: <scientific> { prec engineering? | sgn exp -- adr cnt } \ float: n --
prec 1 < abort" *** F>STRING needs a precision parameter >= 1 ***"
prec exponent to exp
engineering? if
begin exp 3 mod while 10.e f* -1 +to exp -1 +to prec repeat
fdup fabs prec round-off
1000.e f>= if 1000.e f/ 3 +to exp 3 +to prec then
then
prec 1 ?do 10.e f* loop
fnear f>d
dup to sgn dabs <# bl hold
exp #exponent
true to ~#soft prec 1 ?do ~# loop ~.
2dup or if #s
else ~#soft if #s then then
sgn sign #> ;
\ The e is optional, which prevents these numbers from being used in Forth source-code. >FLOAT still works though.
10 constant max-prec \ 11 works sometimes, but fails if the most significant digit is large. 10 always works.
: scientific ( -- adr cnt ) \ float: n --
precision false <scientific> ;
: max-scientific ( -- adr cnt ) \ float: n --
max-prec false <scientific> ;
: engineering ( -- adr cnt ) \ float: n --
precision true <scientific> ;
: max-engineering ( -- adr cnt ) \ float: n --
max-prec true <scientific> ;
2000000001 constant eng-lim \ must be a positive integer
\ In <ENG> any float >= the lim goes to ENGINEERING and otherwise is done without an 'e'
: <eng> ( -- adr cnt lim ) \ float: n --
fdup fabs s>d d>f f>= fdup fabs 1e f< or if engineering exit then
<cstr
fdup f0< if [char] - char+cstr then
fabs
fdup f>d 2dup <big.> <+cstr>
d>f f- \ float: integer-part
fdup f0= 0= if
[char] . char+cstr
precision 0 ?do 10.e f* loop
true to ~#soft
fround f>d <# precision 0 ?do ~# loop #> <+cstr>
then
cstr> count ;
: eng ( -- adr cnt ) \ float: n --
eng-lim <eng> ;
: HOLDS ( adr len -- ) \ HOLD a string
BEGIN DUP WHILE 1- 2DUP CHARS + C@ HOLD REPEAT 2DROP ;
\ HOLDS was written by HAA (he called it $HOLD though):
https://groups.google.com/forum/#!topic/comp.lang.forth/ictps0w02yk