Consulting

Results 1 to 11 of 11

Thread: excel not multiplying correctly

  1. #1

    excel not multiplying correctly

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Sub TEST()
      Q = 3
      P = 0.6
      v=0
      If Format(Q * P, "fixed") = 1.8 Then v = 1 
    
       MsgBox v
    End Sub
    or
    If Format(q * P) = "1.8" Then v = 1

  4. #4
    Thank you Paul and SNB.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,055
    Location
    Quote Originally Posted by NIMANIMA50 View Post
    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

  6. #6
    Quote Originally Posted by Aussiebear View Post
    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. id 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?
    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.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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

  8. #8
    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.

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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
    No, it's not Locked

    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

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,055
    Location
    Quote Originally Posted by NIMANIMA50 View Post
    Aussiebear, "thank you" means guestture of appreciation for those who spent time and effort to provide solution....
    How entertaining... however you have missed the mark again. It's the blandness of your response that I was questioning.
    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

  11. #11
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    I can only second @Aussie.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •