Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / adding to numbers to get 1

Author
Message
Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 14th Dec 2008 11:43
Hi, im trying to make a program that calculates color bands on a resistor. All i need is someone to help we will this part, I need to put two seperate numbers to get one.
ex. 4 and 6 to get 46
ex. 2 and 7 to get 27
NOT 2+7 because that will get 8

any ideas anyone?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Dec 2008 12:18
Use STR$ or maths:


The first method will give you a string result, the second will give you a numeric result.

BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 14th Dec 2008 12:25
wait.... 2+7 = 8? Wow, I probably need to brush up on my maths before I continue programming
Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 14th Dec 2008 20:40
heh, I mean 1+7=8, I just got stiches in my eye from sledding and it was 2 in the morning so I was a bit off. Thanks IanM.
Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 14th Dec 2008 22:45
also, i have ran into another problem,


one=3
two=4
muly=100000



full=one*10+two
answer#=full*muly
if answer#=>1000 :pant=1
if answer#<1000000 then extra$="k" :answer#=answer#/1000
endif
if answer#=>1000000 then extra$="m" :answer#=answer#/1000000



for some reason when the one=anynumber>0 and two is anynumber>0 and the multiplier is 100 000, it always answers

ex. 3.400000000000091

i want just want 2 digits, but indead it gives me alot more
Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 14th Dec 2008 23:06
sorry for the triple post, but heres a better example

do
a#=1.2
b#=1.3
c#=a#*b#
text 50,50,str$(c#)
if upkey()=1 then end
sync
loop
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 14th Dec 2008 23:41
Because of the way floats are stored not all numbers can be stored accurately. Other languages get around it by rounding the output and hiding the innacuracy from the user.

You best bet is to use the second parameter in str$ to set the number of dp you want, so if only 2dp is needed;



Boo!
Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 15th Dec 2008 00:36
that just comes up with an error message for me, is there any other options? like a simple rounding sign or something??
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 01:12
@Rahil45
I tried running the code spooky gave and it worked fine for me. Maybe it's something else that's giving you the problem. Try running just the code he gave by itself and see if that gives you an error and what the error is.

I was therefore I can be.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Dec 2008 01:20
Older versions of DBP don't have the rounding parameter in str, and that may be why you're getting the error. Try upgrading.

Rahil45
16
Years of Service
User Offline
Joined: 31st Jul 2008
Location:
Posted: 15th Dec 2008 01:35
The upgrading worked, as well as the code, thanks
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 01:38
Good to hear that!

I was therefore I can be.
Guyra
18
Years of Service
User Offline
Joined: 10th Nov 2005
Location: Norway
Posted: 16th Dec 2008 23:54
It wouldn't be bad to know that you can change the string back to a value using the VAL() command, either.



Login to post a reply

Server time is: 2024-09-27 22:34:56
Your offset time is: 2024-09-27 22:34:56