|
Post by angelo2449 on Mar 25, 2021 2:02:30 GMT -5
Hi guys,
I have already asked this question but perhaps I have not explained myself well.
I do it now with an example.
With this code, from a list of numbers with different decimals, I want to obtain a list with the numbers rounded to two decimals with the management of + or - 5. To do this, I use the function> using <which however works with the command> print <, so I write the values in a file where I can then retrieve them approximated.
dim A$(10)
A$(1) = "27.9975652"
A$(2) = "15.6985748"
A$(3) = "12.7825415"
A$(4) = "7.9963335"
A$(5) = "13.8589928"
A$(6) = "23.5262584"
A$(7) = "19.2352688"
A$(8) = "20.3625878"
A$(9) = "22.3256985"
open "D:\AltProvvisori\Prova.dat" for output as #1
for i = 1 to 9
print #1, using("##.##", val(A$(i)))
next i
close #1
end
How can I get the same result without writing the file, entrusting the formatted value of A $ (i) to a variable (B $ = using (##. ##, A $ (i)) (wrong)? Tank You
|
|
|
Post by metro on Mar 25, 2021 3:19:34 GMT -5
Is this the result you are after?
dim A$(10),B$(10) A$(1) = "27.9975652" A$(2) = "15.6985748" A$(3) = "12.7825415" A$(4) = "7.9963335" A$(5) = "13.8589928" A$(6) = "23.5262584" A$(7) = "19.2352688" A$(8) = "20.3625878" A$(9) = "22.3256985" for num = 1 to 9 B$(num)= using("##.##", val(A$(num))) A$(num)= using("##.##", val(A$(num))) next
for num = 1 to 10 print A$(num);" Or B$ Val ";B$(num) next
end
|
|
|
Post by Rod on Mar 25, 2021 3:59:12 GMT -5
Yes, using needs a numeric type, you had that correct in the upper code. Also as Metro shows you don't need to introduce a second variable just reformat the first.
|
|
|
Post by angelo2449 on Mar 25, 2021 4:56:47 GMT -5
Perfect, that's what I want! Thank you
|
|