??? 11/25/04 11:47 Read: times |
#81914 - Format Responding to: ???'s previous message |
what do you want 1. float 9.801E+07 into long 98010000; 2. string "9.801E+07" to string "98010000" 2. string "9.801E+07" to string long 98010000 I guess he wants float to string for display purposes, which can be done in a very small string handling routine. Dunno if there is a standard C function, but there is in my Pascal compiler ! And I have written similar routines in Pascal in around 8 lines of code. This code is ancient hack to get round real-string issues in another compiler. Its more than 20 years old ! The STR procedure is a standard function to turn a number into a string, but it can't handle scientific notation The VAL function turns strings into numbers. Ureal is the number to be converted Ustr is the resulting string dp is the number of significant figures. <pre> PROCEDURE using( Ureal : REAL; VAR Ustr : STRING[15];dp:BYTE); {procedure to strip normalised REALS and spit them out in a sensible} {format} VAR dum,pos_ctr : BYTE; eb : integer; count : WORD; num:STRING [15]; T_str2:STRING [5]; BEGIN str (Ureal,num); If dp>0 THEN BEGIN Ustr:=''; FOR count:=11 to length (num) DO Ustr:=Ustr+NUM[count]; val (Ustr,eb,dum); {Eb is the exponent} pos_ctr:=3; Ustr:=''; FOR count:=0 to (DP-1) DO BEGIN Ustr:=Ustr+num[pos_ctr]; inc (pos_ctr); END; Ustr:=Ustr+'.'; FOR count:=(DP-1) to 3 DO BEGIN Ustr:=Ustr+num[pos_ctr]; inc (pos_ctr); END; Ustr:=Ustr+'E'; eb:=eb-dp; STR (eb,t_str2); Ustr:=Ustr+t_str2; END ELSE Ustr:=num; END; {of procedure USING} Steve |
Topic | Author | Date |
Scientific notation to normal notation | 01/01/70 00:00 | |
" | 01/01/70 00:00 | |
Notation | 01/01/70 00:00 | |
is this float to long? | 01/01/70 00:00 | |
Format | 01/01/70 00:00 | |
Ooops | 01/01/70 00:00 | |
sprintf | 01/01/70 00:00 | |
Time for clarification | 01/01/70 00:00 | |
" | 01/01/70 00:00 | |
Sprintf | 01/01/70 00:00 | |
" | 01/01/70 00:00 | |
" | 01/01/70 00:00 | |
WYGIWYAF | 01/01/70 00:00 | |
Hi | 01/01/70 00:00 | |
notation problem | 01/01/70 00:00 | |
try sprintf(buffer,"%f",result); | 01/01/70 00:00 | |
New habits | 01/01/70 00:00 | |
Exactly what it says on the tin!![]() | 01/01/70 00:00 |