Could someone please explain why Excel does not calculate the simple multipliaction correctly and return V=0 as a result of the sub.
Sub TEST() Q = 3 P = 0.6 If Q * P = 1.8 Then V = 1 Else V = 0 End Sub
Could someone please explain why Excel does not calculate the simple multipliaction correctly and return V=0 as a result of the sub.
Sub TEST() Q = 3 P = 0.6 If Q * P = 1.8 Then V = 1 Else V = 0 End Sub
Probably due to floating point (Double) multiplication precision
Option Explicit Sub TEST() Dim Q As Double, P As Double, V As Double Q = 3# P = 0.6 If Round(Q * P, 1) = 1.8 Then V = 1# Else V = 0# End If MsgBox V End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
orSub TEST() Q = 3 P = 0.6 v=0 If Format(Q * P, "fixed") = 1.8 Then v = 1 MsgBox v End Sub
If Format(q * P) = "1.8" Then v = 1
Thank you Paul and SNB.
What does that mean? Was it successful, Did it do what you requested? Have you found a solution to your issue? I for one am tired of the ambitious responses where people glib over but mean stuff all. Someone out there in the internet world has gone out of their way to share their knowledge and time to provide a solution to your issue. The Op gives a week inconsiderate response 'Thank you". Did you try the advice offered, what was the results? What didn't work? Its about engagement. If you post a thread or reply that generates a reply? To the people who seemed interested in your issue, did you give them enough information to maintain their interest?
Remember To Do the Following....
Use [Code].... [/Code] tags when posting code to the thread.
Mark your thread as Solved if satisfied by using the Thread Tools options.
If posting the same issue to another forum please show the link
Aussiebear, "thank you" means guestture of appreciation for those who spent time and effort to provide solution.
second, if the solutions provided were not addressing the issue (or not working) , there would be a follow up query.
third, instead of writing all these useless words , it was better to look at the question from another angle and offer other solution and prove your worth.
finally, I suggest that you make yourself more useful and find another way of getting noticed.
You're welcome, and thanks for the 'Thanks'. Many people don't acknowledge that a user or response was useful, or that someone took the time to read and suggest something
If a question asker is satisfied that the query is resolved, the unambiguous way is to use [Tread Tools] above the initial post and mark is as [SOLVED]
Doesn't mean that the thread is locked, and the same path can mark it as unsolved if it turns out there still is an issue
Capture.JPG
Last edited by Paul_Hossler; 04-09-2022 at 04:44 AM.
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
Paul,
Thanks for the suggestion, i already marked it as [SOLVED] but i hope this will not make the post to other users that are willing to suggest other solutions to the question unavailable.
No, it's not LockedDoesn't mean that the thread is locked, and the same path can mark it as unsolved if it turns out there still is an issue
Users can add and searches will find it
As an aside though, we find that many times it's better to start a new thread (possibly referencing the old one) instead of just tagging on to an old one
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
Remember To Do the Following....
Use [Code].... [/Code] tags when posting code to the thread.
Mark your thread as Solved if satisfied by using the Thread Tools options.
If posting the same issue to another forum please show the link
I can only second @Aussie.