intersystems-cache

How to round the result of a division in intersystems cache?


What's the best way to round the result of a division in intersystems cache?

Thanks.


Solution

  • There are some functions, which used to format numbers, as well they would round it if necessary

    $justify(expression,width[,decimal]) - Caché rounds or pads the number of fractional digits in expression to this value.

    write $justify(5/3,0,3)
    1.667
    

    $fnumber(inumber,format,decimal)

    write $fnumber(5/3,"",3)
    1.667
    

    $number(num,format,min,max)

    write $number(5/3,3)
    1.667
    

    $normalize(num,scale)

    w $normalize(5/3,3)
    1.667
    

    You just can choose which of them much more suitable for you. They doing different things, but result could be same.