Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

That's lua! :( -> Prozent Bug!

AnatolyAnatoly Mod
edited December 2015 in Questions Posts: 835

I made a math project, and want to have prozent, and after I clicked 50 % 40 =, and I expected 20 because 50 prozent from 40 is 20 but he answered 40.0 - Is there any way to leave the calculator the real prozent and why 50%40 ~= 20?? WHY????? Thank you for answering!

Tagged:

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,295
        print(50%40)
    

    returns 10, as it should.

  • Posts: 1,976

    The % operator is for modulus, not percentages. If you want to get 50% of 40, use 0.5 * 40.

  • The % is the rest of division, not the percentage

  • dave1707dave1707 Mod
    Posts: 7,741

    @TokOut 50 % 40 isn't 50 percent of 40. % is a module division which give you the remainder of 50 divided by 40 which is 10. So 50 % 40 is 50 divided by 40 which is 1 with a remainder of 10. Again, if you READ the reference it will tell you these things.

  • And as @dave1707 said 'we are not here to teach you'
  • AnatolyAnatoly Mod
    Posts: 835

    Isn't any formule instead of 50 % 40 doing 50% * 40 or something like this

  • Jmv38Jmv38 Mod
    Posts: 3,295

    this is embarassing... Think a little about it and you'll get a very simple formula.

  • Posts: 116

    He is not here to think. We should think for him

  • AnatolyAnatoly Mod
    Posts: 835

    If number2 % number is false then is (number2/100) * number true, right?

  • AnatolyAnatoly Mod
    edited December 2015 Posts: 835

    Because if 50%40 returns 10 then (50/100)*40 returns 20 - IT SHOULD WORK, I go to test

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Good job! You see you could find it yourself.

  • AnatolyAnatoly Mod
    Posts: 835

    The mod - mode at the calculator is bugging with this code

            answernumber = number2/number
            answernumber = answernumber - math.ceil(answernumber)
            txt.value = txt.balue .. " = " .. answernumber
    

    But can you please help me this code, he insults this into an error why? Thanks for the help! I tried since yesterday to solve the code. Because 6 mod 5 = 1 and
    6 : 5 = 1 R1 - he insults and arithmetic error, but with div he is making all nice:
    100 : 8 = 12 R4 and 100 div 8 = 12 and in div instead answernumber - math.ceil(answernumber) I had math.ceil(answernumber)

  • Posts: 2,020

    @TokOut if you tap an error that you get in the console, it will be copied to the pasteboard. Then you can paste it in the forum, so that people can see what error you are getting.

  • AnatolyAnatoly Mod
    Posts: 835

    Functionality:147: attempt to concatenate a nil value (field 'balue')
    stack traceback:
    Functionality:147: in function 'answer'
    Main:98: in field 'action'
    Button:64: in method 'touched'
    Main:215: in function 'touched'

  • AnatolyAnatoly Mod
    Posts: 835

    Solved, I didn't see that I use txt.balue instead txt.value

  • dave1707dave1707 Mod
    edited December 2015 Posts: 7,741

    @TokOut It's the same thing over and over. You keep asking us to solve your problem when you're being told exactly what's wrong. The error message tells you exactly what your problem is. You're trying to concatenate a nil value to something else. The variable balue is nil. Look at your code and see why you're not moving something to balue before you're using it.

  • AnatolyAnatoly Mod
    Posts: 835

    That's not the meaning of my calculator. Just download it with https://gist.github.com/TokOut/b540d05e60bb49c644d8 and something with http.request and try it yourself

  • IgnatzIgnatz Mod
    Posts: 5,396

    @TokOut - what dave1707 is saying, is that you need to learn to debug your own code, and he is trying to show you how to do it.

    We can't solve every simple little problem for you.

  • AnatolyAnatoly Mod
    Posts: 835

    Ok

Sign In or Register to comment.