5

Say there is two attributes, 1 and 3.

Dividing them using Lightning expressions will display something like 0.33333333, but I'd prefer to see 0.33.

How do I format them without going into JS controller? Seems like there aren't any official functions.

1
  • Did the supplied answers not do what you wanted Commented Aug 25, 2016 at 1:21

2 Answers 2

6

What about using format in outPutNumber :

<ui:outPutNumber aura:id="myNumberFormat" format="#,##0,000.00" value="0.33333333"/>

Reference here

1
  • That looks like a best approach. I ended up using JS though: Math.round((a-b) * 100) / 100
    – dzh
    Commented Aug 25, 2016 at 12:51
3

How about using some Math™ (implementing floor using mod to make a truncation function):

floor(n) = n - (n % 1)

From floor, if we feed in a number that has been multiplied by 100, apply floor and then divide by 100, we have a rounding (or at least truncation)

truncate (n,2) = ((n*100) - ((n*100) % 1))/100

Which can be expressed, in lightning as:

<ui:outputText value="{!((v.testval*100)-mod((v.testval*100),1))/100}"/>

And of course, using your two attributes:

<ui:outputText value="{!(((v.testval1/v.testval2)*100)-mod(((v.testval1/v.testval2)*100),1))/100}"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .