|
- Forum - iziBasic
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Sujet n° 1613 |
Rounding up of numbers |
le 03/05/2008 @ 22:31 par trent
|
Hello, I am having a wonderful time programming my Zire 72 with iziBasic. I am gradually learning how to convert my Basic programs into iziBasic. I just finnished a program for my job today and it works great, but I am having problems rounding up numbers. I have read the manual and it pretty much just says: "Round v/n" That doesn't help me much. Here is an example line of my code that I need to round up. %CPV%=%Hc%-%Lc%/10 The answer may come as 55.2 or 55.8 etc. I need to round %CPV% up to the next whole number. Can somebody please help me ? Thanks in advance. -trent-
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 1 -------- le 04/05/2008 @ 00:23 par nate Weil
visiteur |
v/n means variable/number just in case that's what you're asking. You would simply do Round %CPV% and it would round it up. You have something wrong with that line of code though... you can only have one operator per line of code doing math. So instead of %CPV%=%Hc%-%Lc%/10 you have to do %Lc%=%Lc%/10 %CPV%=%Hc%-%Lc% Hope that helps! Nate |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 2 -------- le 04/05/2008 @ 04:05 par trent
visiteur |
Hi Nate, The code compiles and runs the way I have it written. No problem there. But I tried entering Round %CPV% on the following line and then I get a Syntax error for the Round %CPV% line. Cheers, Trent.
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 3 -------- le 04/05/2008 @ 11:12 par aldweb
visiteur |
Hello,
ROUND() is a function so it will just need parentheses to work: %CPV%=%Hc%-%Lc%/10 %CPV%=ROUND(%CPV%)
ROUND() returns the closest integer, so ROUND(1.2) will return 1 and ROUND(1.7) will return 2. if you need 1.2 to return 2, you should modify your source code accordingly: %CPV%=%Hc%-%Lc%/10+0.5 %CPV%=ROUND(%CPV%)
"you can only have one operator per line of code doing math." Nate, please allow me to rectify this sentence. One operator is required in a function, so ROUND(%Hc%-%Lc%/10) does not work in iziBasic. BUT math assignations can have more parameters, so %CPV%=%Hc%-%Lc%/10 works fine. Math assignations will work according to the PARSER compiling directive. If PARSER is set to OFF (default value, a left over from the early version of iziBasic), the compiler will build the code this way: %CPV%=(%Hc%-%Lc%)/10 If PARSER is set to ON, the compiler will build the code this way: %CPV%=%Hc%-(%Lc%/10)
Cheers, aldweb |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 4 -------- le 04/05/2008 @ 14:51 par Nate Weil
visiteur |
ok sorry my bad. I didn't know IF-ENDIF is a function... and just to be at least partly helpful :D functions always have to have a v=function() "structure". Then v equals whatever the function returns. And the easiest way, if you're reading the manual to tell what a function is is to look at its description and see if it says blah blah blah returns blah blah blah. The word return is the key. Thanks for correcting me aldweb :) and good luck trent! |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 5 -------- le 04/05/2008 @ 17:45 par aldweb
visiteur |
Nate, I didn't correct you, I would never do that. I just rectified one of your sentences, with the objective of helping you (and others).
IF/ENDIF is a statement, not a math assignment... Nevertheless, this is maybe the main limitation of iziBasic that it requires to preprocess some calculations to be used in statements and functions. One would maybe want to do "IF A=ROUND(B*5.5) THEN..." instead of "C=B*5.5:C=ROUND(C):IF A=C THEN". The result is the same, it just requires a little bit of mental work to get accustomed to this specificity of iziBasic... This is something I have wanted to work on since ages, but I have always been enhancing iziBasic in other areas before...
And, this is a scoop, version 8.0 of iziBasic is on tracks, with a lot of new features: IR communications, Network communications, linking scrollbars and fields, 5WayNav, 320x480 HighRes+ mode, and many other goodies. I hope to release it by the end of May.
Cheers, aldweb
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 6 -------- le 04/05/2008 @ 17:54 par trent
visiteur |
Hello, As usual you took care of the problem. It works fine now. Thanks so much ! Cheers, -trent- |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 7 -------- le 04/05/2008 @ 18:14 par Nate Weil
visiteur |
lol same dif whatever you want to call it thanks anyways :D stop giving it away I'm excited enough as it is lol seriously I can not wait for june... though that's also cuz of the wwdc. |
|
|
sujet actif
sujet clos
Important!
Nouveau message -
Rectifier message
Clôturer sujet
Remonter
|
|