Announcement

Collapse
No announcement yet.

round up with formula floating point numbers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • round up with formula floating point numbers

    Hi
    Does anyone have an idea how to always round up with formula floating point numbers?
    Example: 2,2 to 3 or 4,4 to 5 or 8.5 to 9
    peter

  • #2
    Hello
    In php you have such functions for this http://php.net/manual/en/function.round.php and http://php.net/manual/en/function.ceil.php
    https://www.espocrm.com/documentatio...on-in-formula/ manual for creating new function in formula

    implement it if exists round function (application/Espo/Core/Formula/Functions/NumberGroup/RoundType.php) or create a new one for Ceil

    Comment


    • #3
      Hi Peter,

      Try this:
      value = ifThenElse(value % 1 > 0, number\round(value + (1 - value % 1) + 0.00001), value);

      But I didn't tested.

      Comment


      • #4
        I'm trying to round off a value with the formula but failing at the moment. It just keep displaying value. I'm calculating as following. (Comments is in /* */) All field is Currency Field.

        Gross=quantity*price /* Gross is read only field, quanity is 1, price is $855) */
        Discount=gross*0.095 /* Gross is $855, 0.095 mean 9.5% */

        Issue is my Discount is showing up as $81.22 (true value is $81.225), I have tried the following code but it all fail to work. Not sure where I'm doing it wrong. Basically I want to make it show $81.23 (some formula I use below is to trial-and-error for a working formula).

        Discount=gross*0.095
        number\ceil(Discount)

        Discount=gross*0.095
        number\round(Discount, 2)

        Discount=gross*0.095
        number\round(Discount, 0)

        number\round(Discount,0)=gross*0.095

        number\round(Discount,2)=gross*0.095

        number\round(Discount=gross*0.095,0)

        number\round(Discount=gross*0.095,2)

        number\ceil(Discount,2)=gross*0.095

        number\ceil(Discount=gross*0.095,2)

        Comment


        • #5
          Hi,
          use this
          Code:
          fieldName = number\round(discount, 3)
          Note!
          You used the field name as 'Discount'.
          Is this a real field name? If so, it should start from the lower case letter (e.g. discount).
          Is this a variable? If so, it should start with '$' symbol (e.g. $Discount).

          Comment


          • #6
            Originally posted by Maximus View Post
            You used the field name as 'Discount'.
            Is this a real field name? If so, it should start from the lower case letter (e.g. discount).
            Is this a variable? If so, it should start with '$' symbol (e.g. $Discount).
            Thank you so much. It is working now. That was one variation I didn't think of trying and totally missed it. In relation to Discount, yes I aware of field case sensitivity, it was actually just example formula so the code look easier to read in the example. And you though far ahead, also give tip on Variable too (I'm not at that level to use Variable yet).
            ---
            For the code above here is my variation

            discount= number\round(gross*0.095, 2)

            Comment

            Working...
            X