Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

[SOLVED] How to remove the numbers after the point?


Question

Posted (edited)

I'm preparing a stage for heating. There is a need for temperature division. As a result, we obtain fractions

 

Please login or register to see this attachment.

 

I need only 2 numbers after the point. How can I do that?

I'm just starting to make a scene and I have so far only this code

Please login or register to see this spoiler.

 

Edited by Flash226

9 answers to this question

Recommended Posts

  • 0
Posted (edited)

function roundit(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

 

 

you can then call the function and specify the idp (decimal places you want)

Edited by shaunfrost
  • 0
  • Inquirer
  • Posted

    I'm not strong at lua. Only I study. Can you tell where exactly you need to insert a function call?

    For example, for 

    pices = (gisterezistfloor/35);

     

    Debug returns 0.1851428571429

    • 0
    Posted
    5 minutes ago, Flash226 said:

    I'm not strong at lua. Only I study. Can you tell where exactly you need to insert a function call?

    For example, for 

    pices = (gisterezistfloor/35);

     

    Debug returns 0.1851428571429

    Please login or register to see this code.

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    It works. Perfectly. Thank you.
     

    • 0
    Posted (edited)
    1 hour ago, Flash226 said:

    fibaro:debug("tfloor = "..tfloor.."");

     

    can be also done like this:

    Please login or register to see this code.

    where number between dot and 'f' is number of decimal places. Of course this function also rounds number correctly!

     

    Edited by Sankotronic
    • 0
  • Inquirer
  • Posted

    Now I'm faced with another problem.
    It is necessary

    if tfloor> 28 then tfloor = 28


    Any ideas how to do this?

    • 0
    Posted
    14 minutes ago, Flash226 said:

    Now I'm faced with another problem.
    It is necessary

    if tfloor> 28 then tfloor = 28


    Any ideas how to do this?

    Not quite sure what you mean, but you almost wrote it out yourself...

     

    if (tfloor >= 28) then

    tfloor = 28

    end

     

    of course if you put that in a loop you will be in trouble.

    • 0
  • Inquirer
  • Posted (edited)

    Working. I missed the word "end" and that's why I did not work. 

    But still I need it to be in a loop

    I think this will not work

     

    Please login or register to see this code.

     

    Edited by Flash226
    • 0
  • Inquirer
  • Posted (edited)

    I tested it and it works. Thank you all for your help.

    Edited by Flash226

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...