View previous topic :: View next topic |
Author |
Message |
daro
Joined: 15 Nov 2010 Posts: 25
|
Posted: Thu Sep 09, 2021 9:49 am Post subject: 7 digit LED Calculator, single, and double operation. |
|
|
Hi,
i making 7 digit LED calculator, and have problem with result, after operation on single and double operation.
I input data from keyboard switches into string:
Code: | Dim Number1 As String * 8
Dim Num As String * 10
Number1 = Number1 + Num 'Num is select by switches. |
Same for next operand (Number 2)..As Num you can type dot "." into string to type single number.
Next convert:
Code: | Dim Operand1 As Double
Dim Operand2 As Double
Dim Result As Double
Operand1 = Val(number1)
Operand2 = Val(number2)
Result = Operand1 + Operand2 |
Now we never know what result is, so never know how long fraction of a Double is.
I trying to INT, and FRAC function but it seems to not work with Double? Single is not enough accurate for me.
Other method is:
Code: | Num = Str(result)
Pos = Charpos(num , ".") 'calc dot position on LED display
Pos = Pos - 1
Dot(pos) = 1
Delchars Num , "."
For I = 1 To 7
Str_array(i) = Mid(num , I , 1)
Dig(i) = Val(str_array(i))
Next |
but this result tralling zeros after number (after fraction part).
And is problem with dot position. For example:
111.222+333.444=444.666, and dot position from Pos = Charpos(num , ".") is correct, but 1111.222+3333.444=4444.666, and position is calculated wrong, becouse for example 4444.666 schould be Pos=5, but is 2...why?
For example 111.22 + 333.44, result display: 444.6600 (last two zeros are not needed), schould display _ _ 444.66. _ _ is leading off digits...
What is better way to convert result from a single/double, to array of digit for 7 digit LED display? (without tralling zeros after fraction part)
(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.4 )
EDIT. It seems them Charpos function (Pos = Charpos(num , Search_str)) not work propertly with Double data. When I change Result fot Single, Pos is calculated corectly.
So how to convert Double result in string, or 7 byte array, and read coma position? |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Thu Sep 09, 2021 8:24 pm Post subject: |
|
|
Daro,
Show us your complete code that's not working.
Code from EDC is working, so maybe you do something else wrong.
Low stack? _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|