You can help by commenting or suggesting your edit directly into the transcript. We'll review any changes before posting them. All comments are completely anonymous. For any comments that need a reply, consider emailing training@inductiveautomation.com.
Version:
LESSON LIST
-
6:04Map Transform
-
5:12Format Transform
-
2:29Script Transform
-
3:22Expression Transform
LESSON
Format Transform
Description
The Format Transform provides an easy means of applying numerical or date formating to the results of a binding.
Video recorded using: Ignition 8.0
Transcript
(open in window)[00:00] In this lesson we'll take a look at the Format Transform. The Format Transform allows you to take a numerical value or a date value, and change the formatting of it for the binding. So, in my View I have two Labels. One of which has a number on it, and that's because it's bound to this Memory Tag here. It's currently set to a float. Let's examine this binding. So, with that component selected, I'll head over to the text property, and click the binding icon. We'll press the Add Transform button. And I'll select Format. Click Add Transform once more. And we can see the Format Transform. So again, there's really two types. Right now we're using the numeric type. Later on I'll switch over and show you the datetime. Now, for both types of transforms, they do have a locale selector, which tries to automatically detect which locale you're in. So, the part of the world I'm in right now uses a period as a decimal separator. But if I were to change the locale selector to another part of the world that uses say, a comma, such as Bulgaria. If I hit apply, here, you can see it down below in the preview, but you can definitely see it a little bit easier on the binding. So, we're not changing what's on the source of the binding in this case here. Instead, we're taking that value, we're applying some formatting, and then returning that updated value to the property on the component. Now, I'll switch the locale back to auto. And with the format drop down, this has a bunch of options on how to format. So for example, I could switch it to integer, where it just drops the decimal value, here. I could switch it to a currency, where it adds a character in front to denote that this is a currency based on the region of the world I'm in. I could come up here and select percent, which shows it as a percentage. Or I could select pattern. Pattern allows me to explicitly define what the format should be. Now, in this label, maybe this is showing off a total. So I could actually just type the word total, and have that be effectively a prefix. To represent your number, you use the pound or the hash character. So I could put some down here for my decimal separator, and a couple more and you can see down below it's showing the decimal value now. You may have seen this notation elsewhere in Ignition. That character really means just show significant values at that position. So for example, with the decimal values here, if I wanted to always show two decimal positions, even if the second one or either of them are zero, I could replace that character with some zeroes. And you can see down below we're actually forcing that decimal position. So if you needed to apply some formatting or add a prefix or a suffix to a binding, you could potentially use this transform. That's enough for the numeric type. Let's take a look at the datetime. So I'm going to hit OK, here. And on my next label. Let's take a look at the binding on the text property here. And I'll use an expression this time. We'll use the nowexpression function to get the current time. And then we'll set it to a one-minute poll. Let's add another transform here. We'll select Format, yet again. And then we'll go ahead and switch over to the datetime type. So again we have the locale as well as the time zone if you needed to override the time zone. The format drop down allows you to specify a date, a time, a datetime, or a pattern you type yourself. To demonstrate, if I select date, we no longer show the time, and I get this easy little drop down I can use to define how expansive we should be with the date. So if I select full, you can see that it actually includes the day of the week, as well as spelling out the month. If I switch this to short, it gives us a more compact version of the date. I'll head back to format. If I switch to time, you can see it does something similar, except now we're looking at the time instead of the date. I can still use this drop down. It's now the time drop down. And either select full, short or something in between. Now if I come back up to format, and I pick datetime, it gives me both. So I can kind of combine them however I want. Now if you wanted a little more control, here though, you could with the format drop down select pattern, and then you type in what exactly it is you want to see. Again, this uses another kind of formatting pattern you'd see elsewhere in Ignition, where certain letters denote different units of time. So for example, capital M would be the month. And more sequential characters spell out that unit of time a bit more. So if I add a third M here, it'll actually give me the first three letters of the month. If I add a fourth one, it'll spell out the month for me. If you're interested in learning about the other characters, take a look at the user manual for more information. But hopefully that gives you a good idea about what the Format Transform does. Again, it's a very easy way to apply different formatting to numbers and dates.