|
Post by alexfish on Dec 4, 2023 15:29:04 GMT 1
Hi All
A simple STR$ to decimal place
Have Nicked EVAL & used as EVAL$ , can change the function Name if a problem
OPTION PARSE FALSE USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH
FUNCTION EVAL$(double hug_number,int decimal_places) TYPE STRING LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION
PRINT "This Number " , EVAL$(22.9697776,2)
PRINT "This Number " , EVAL$(SQR(22.9697776)*SIN(5.9/8*PI),2)
BR Alex
|
|
|
Post by alexfish on Dec 4, 2023 23:10:18 GMT 1
Here have put the FUNCTION into inlude.bac myeval.bac the code USEH #define PRINTS(arg1,arg2,arg3) sprintf(arg3,arg2,arg1) END USEH PROTO PRINTS FUNCTION EVAL$(double hug_number,int decimal_places) TYPE STRING LOCAL EVS$ IF decimal_places > -1 THEN
EVS$ ="%." & STR$(decimal_places) & "f" LOCAL gx[20] TYPE static char
PRINTS(hug_number,EVS$,gx)
RETURN gx
ELSE RETURN NULL END IF
END FUNCTION Typical USAGE in hug use LIST INCLUDE "hug.bac"
INCLUDE "myeval.bac"
LOCAL LOCAL txt$, rpl$ win =WINDOW("Eval$",606,406) lst = LIST(300,400) FONT(lst,"monospace 16px") ATTACH(win,lst,3,2) LOCAL r 'Format to TEXT(lst,"CASH") FOR t = 1 TO 20 txt$=EVAL$(t,2) rpl$= SPC$(8-LEN(txt$)) TEXT(lst,rpl$ & txt$) NEXT
DISPLAY BR Alex Attachments:
|
|
|
Post by alexfish on Dec 5, 2023 4:11:57 GMT 1
Improved version Gives Total INCLUDE "hug.bac" INCLUDE "myeval.bac"
LOCAL LOCAL txt$, rpl$ LOCAL tot TYPE double win =WINDOW("Eval$",606,406) lst = LIST(300,400) FONT(lst,"monospace 16px") ATTACH(win,lst,3,2) LOCAL r 'Format to TEXT(lst," MY CASH")
FOR t = 0 TO 15 tot = tot +t txt$=EVAL$(t,2) rpl$= SPC$(32-LEN(txt$)) TEXT(lst,rpl$ & txt$) NEXT FOR t = 100 TO 109 tot = tot + t + 0.1 txt$=EVAL$(t + 0.1,2) rpl$= SPC$(32-LEN(txt$)) TEXT(lst, rpl$ & txt$) NEXT txt$="TOTAL £" & EVAL$(tot,2) rpl$= SPC$(33-LEN(txt$))
TEXT(lst, rpl$ & txt$)
DISPLAY depending on keyboard if want '€' Press AltGr ($) BR Alex Attachments:
|
|