2

I need to show some definite number of decimal digit in my output [length of decimal digit is returned by stored procedure] and length of these decimal digits vary.However I do not need to care integer part it just decimal I have to worry about.Hence I used number pipe. This works fine till I pass hard coded value like this:

{{transaction.Rate| number :'.2-3'}}

It shows expected value: 713.753 [I do not care integer part]

However I have a field in transaction model called RateDecimal. I want to pass this field instead of '3' in above snippet.

{{transaction.Rate | number :'.2-`transaction.RateDecimal`'}}

It throws error. How to pass the same?Thanks for your help.

2 Answers 2

4

I am adding my working example here:

{{transaction.ExchangeRate | number : '.2-' + transaction.CustomerRateDecimal}}

The above thing works for me as number pipe expects values in quotes for decimal part hence concatenate is playing good here.

Sign up to request clarification or add additional context in comments.

6 Comments

The standard number filter wants a numeric parameter
It takes a string as well as long as it is a valid number.
but '.2-' concatenated to a string is not a valid number.
Yeah you're right. I just reread the question. I'm not sure why I thought adding a hyphen in a number would be valid.
@dkaramazov: In fact your earlier suggestion worked as I think I am looking only after decimal digit hence it has to be concatanated with decimal string .Let me know your thought.Sorry for posting too early.
|
1

Try this: {{transaction.Rate | number:transaction.RateDecimal}}

3 Comments

Yes that works .I missed to state in my question that I needed minimum number of decimal digit too.
Perhaps {{transaction.Rate | number:Math.min(transaction.RateDecimal,2)}} but I'm not sure if it will be able to call the min function in that expression. You might have to implement your own custom filter.
Ohh looks like I was too early to say , it breaks if I just provide {{transaction.Rate | number:transaction.RateDecimal}} .However this worked: `number :'.1-'+ transaction.CustomerRateDecimal'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.