Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
ma-point-value: number formatting
-
I have an ma-point-value like so. By default it prints out 2 decimal places.
How can I change the format to zero digits after decimal, or other formats?
<ma-point-value id="dp-m1-houses" style="width: 40%; height: 25px; text-align: left; margin-left: 20px;" point-xid="DP_4d6ba9d6-116a-4922-9841-515a22710174" enable-popup="hide"></ma-point-value>
Default format:
Thanks,
Alex -
You can use in the text format settings for the respective points on the data sources page /data_sources.shtm (this applies to the rendered value only)
Alternatively:
Use
<ma-get-point-value point-xid="DP_4d6ba9d6-116a-4922-9841-515a22710174" point="point"></ma-get-point-value>
instead and with the point attribute use:{{parseInt(point.value)}}
for only one decimal place use{{ point.value.toFixed(1)}}
Plenty of resources are available in the vanilla javascript Math class:
https://devdocs.io/javascript-math/Hope that helps
Fox
-
@mattfox said
instead and with the point attribute use:
{{parseInt(point.value)}}
for only one decimal place use{{ point.value.toFixed(1)}}
Oh, you can use javascript functions inside the brackets of html ? I thought that you can only do basic math functions inside the brackets.
Good to know @MattFox :)
-
You can albeit only the basic ones. As you will have discovered, anything requiring more than simple logic will need a component or a controller to manipulate data.
-
@mattfox said in ma-point-value: number formatting:
point.value.toFixed(1)
you can also use a built-in Angular filter -
{{point.value | number(decimal places)}}...even when doing things you can't do more than basics - like
{{point.value*256 | number(1)}}edit. Jared Wiltshire - examples given here are incorrect, see post by @Puckfist below.
-
Also true, but not everyone on this forum likes to play with JavaScript and are quite content with using what is available without making things too difficult for themselves.
-
Excuse me @MattFox - I thought you were discussing a javascript method solution in your answer. And, to your point, quite often what is "available" in the wonderful collection of Mango is not entirely obvious without a lot of time searching in multiple places - so some of us need to be content to use what we know. I'll try to refrain from suggesting javascript (actually angular components) in the future.
-
Far from it, if you have a solution that can benefit someone, show it and give examples. That's what this forum is for. All I am saying is that not everyone is comfortable as soon as you start mentioning filters or components etc.
Yes what you have done works but sometimes simplicity is key. -
It's definitely good to contribute methods of doing stuff, but it's best if those methods work (insert links to the many times I've said "untested" next to code snippets here...)
I think your parameters to the angular filter have a syntax error, they should be colon delimited, as,
{{point.value | number:N}}
where N is the number of decimal places, like,
{{point.value*256 | number:1}}
-
Correct! and point well taken - absolutely dumb mistake.