Price fraction: Difference between revisions
Content added Content deleted
m (Grouping BASIC dialects) |
(Price fraction in True BASIC and Yabasic) |
||
Line 1,331: | Line 1,331: | ||
Gimme a number?34.12 |
Gimme a number?34.12 |
||
34.12 -->0.26</pre> |
34.12 -->0.26</pre> |
||
==={{header|True BASIC}}=== |
|||
{{trans|BASIC}} |
|||
<syntaxhighlight lang="qbasic">FUNCTION pricefraction(price) |
|||
!returns price unchanged if invalid value |
|||
SELECT CASE price |
|||
CASE IS < 0 |
|||
LET pricefraction = price |
|||
CASE IS < .06 |
|||
LET pricefraction = .1 |
|||
CASE IS < .11 |
|||
LET pricefraction = .18 |
|||
CASE IS < .16 |
|||
LET pricefraction = .26 |
|||
CASE IS < .21 |
|||
LET pricefraction = .32 |
|||
CASE IS < .26 |
|||
LET pricefraction = .38 |
|||
CASE IS < .31 |
|||
LET pricefraction = .44 |
|||
CASE IS < .36 |
|||
LET pricefraction = .5 |
|||
CASE IS < .41 |
|||
LET pricefraction = .54 |
|||
CASE IS < .46 |
|||
LET pricefraction = .58 |
|||
CASE IS < .51 |
|||
LET pricefraction = .62 |
|||
CASE IS < .56 |
|||
LET pricefraction = .66 |
|||
CASE IS < .61 |
|||
LET pricefraction = .7 |
|||
CASE IS < .66 |
|||
LET pricefraction = .74 |
|||
CASE IS < .71 |
|||
LET pricefraction = .78 |
|||
CASE IS < .76 |
|||
LET pricefraction = .82 |
|||
CASE IS < .81 |
|||
LET pricefraction = .86 |
|||
CASE IS < .86 |
|||
LET pricefraction = .9 |
|||
CASE IS < .91 |
|||
LET pricefraction = .94 |
|||
CASE IS < .96 |
|||
LET pricefraction = .98 |
|||
CASE IS < 1.01 |
|||
LET pricefraction = 1 |
|||
CASE ELSE |
|||
LET pricefraction = price |
|||
END SELECT |
|||
END FUNCTION |
|||
RANDOMIZE |
|||
FOR i = 1 TO 100 |
|||
LET d = RND |
|||
PRINT USING "#.##": d; |
|||
PRINT " -> "; |
|||
PRINT USING "#.## ": pricefraction(d); |
|||
IF REMAINDER(i,5) = 0 THEN PRINT |
|||
NEXT i |
|||
END</syntaxhighlight> |
|||
==={{header|uBasic/4tH}}=== |
==={{header|uBasic/4tH}}=== |
||
Line 1,412: | Line 1,474: | ||
0 := 0.1 |
0 := 0.1 |
||
0.7388727 := 0.82</pre> |
0.7388727 := 0.82</pre> |
||
==={{header|Yabasic}}=== |
|||
{{trans|BASIC256}} |
|||
<syntaxhighlight lang="vb">data 10, 18, 26, 32, 38, 44, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 100 |
|||
data 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96 |
|||
dim od(21) |
|||
for i = 1 to 20 |
|||
read oldDec |
|||
od(i) = oldDec |
|||
next i |
|||
dim nd(20) |
|||
for j = 1 to 19 |
|||
read newDec |
|||
nd(j) = newDec |
|||
next j |
|||
for i = 1 to 100 |
|||
for j = 1 to arraysize(nd(),1)-1 |
|||
if i < nd(j) break |
|||
next j |
|||
print (i/100) using ("#.##"), " -> ", (od(j)/100) using ("#.##"), "\t"; |
|||
if mod(i, 5) = 0 print |
|||
next i |
|||
end</syntaxhighlight> |
|||
=={{header|Beads}}== |
=={{header|Beads}}== |