hero
Home About Hardware Guide

Categories

Archive

June 2024

May 2024

April 2024

March 2024

February 2024

January 2024

December 2023

November 2023

October 2023

September 2023

August 2023

July 2023

June 2023

May 2023

April 2023

March 2023

February 2023

January 2023

December 2022

back to home

Dismantle Number Value Formatting

10 April 2023 • 3 mins

Please note, that the content of this article might not be aligned with the latest version of Pakboard designer or runtime but applies to an older version

Displaying numbers in the correct format is one of the fundamental tasks of building a board. The basic features of number formatting in Peakboard are quite easy and well documented. Please check out the documentation, if you’re not familiar with the formatting combo box that can be found everywhere. This article digs a bit deeper into how to format a number when options in the combo box are insufficient.

Please note: It’s on the 2023 roadmap to rework the entire system of formatting numbers in Peakboard. This article uses the March 2023 version of Peakboard.

Besides the standard formatting from the combo box, there is an option to build your own formatting pattern. A formatting pattern consists of the pattern itself (represented by characters like #, 0, etc.), and the locale. The locale represents the cultural background of the format, e.g. Germans use a , as a decimal separator, while Americans use a ..

Let’s start with a simple example. The pattern ##.## says that we want two digits before and two digits after the decimal separator.

image

So if the locale is de-DE for Germany, it will generate 12,34. If the locale is en-US for American, it will generate 12.34.

The next formatting character to understand is 0. 0 is almost the same as #, but it will print a 0 if the original number doesn’t have enough digits. The number 12 will be turned into 12 when applying ###, but it will be turned into 012 when applying 000. So you can easily get leading zeros, if you want some.

image

In lots of cases, it may be necessary to provide a unit along with the number. Feel free to just add it to the pattern. You can do this even with Unicode characters like a degree symbol.

image

Here is our sample in action. BTW: the source is a public OPC UA server; feel free to download the sample pbmx and play around with it yourself….

image

Is there even more formatting madness?

Yes, there’s a lot more you can do to format your numbers as perfectly as possible. The format strings we learned about in this article are only a small subset of what is possible. Please check out the official documentation provided by Microsoft. All the option are available in Peakboard.

Dismantle Number Value Formatting

Newsletter

Want to get notified when a new article is published? Sign up below!