User Tools

Site Tools


dictionary:more:formatnumber

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dictionary:more:formatnumber [2016/05/25 18:31] – external edit 127.0.0.1dictionary:more:formatnumber [2023/02/13 14:52] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====format number==== ====format number====
 Formats a number in a specific way given the format string. Similar to the format() command. This same format is supported for both the **format number** verb and the format string parameter of a Unit that controls it’s display of a numerical value. Formats a number in a specific way given the format string. Similar to the format() command. This same format is supported for both the **format number** verb and the format string parameter of a Unit that controls it’s display of a numerical value.
 +
 +The formatting syntax is also used to format the outgoing message for a numerical value going to an MQTT server via the [[supported_hardware:mqtt|MQTT Plugin]].
  
 ===Usage:=== ===Usage:===
Line 17: Line 19:
 | - | displays the minus sign to the left of the number if the number is negative, makes no change if the number is positive.| | - | displays the minus sign to the left of the number if the number is negative, makes no change if the number is positive.|
 | E or e | displays the number in scientific notation.| | E or e | displays the number in scientific notation.|
-| \character | displays the character that follows the backslash.|+| \character | displays the character that follows the backslash. When using with the verb in applescript you will need to double slash this. See applescript usage note below.|
  
 additionally the string may contain 3 formats separated by semicolons to be used when the number is positive, negative or zero. additionally the string may contain 3 formats separated by semicolons to be used when the number is positive, negative or zero.
Line 26: Line 28:
 |#.0000|1.3|1.3000| |#.0000|1.3|1.3000|
 |0000|5|0005| |0000|5|0005|
 +|#.#\ \°\F|75.621|75.6 °F|
 |#%|0.25|25%| |#%|0.25|25%|
 |###,###.##|145678.5|145,678.5| |###,###.##|145678.5|145,678.5|
Line 31: Line 34:
 |-#.##|-3.7|-3.7| |-#.##|-3.7|-3.7|
 |+#.##|3.7|+3.7| |+#.##|3.7|+3.7|
-|#.##;(#.##);/z/e/r/o|3.7|3.7| +|#.##;(#.##);\z\e\r\o|3.7|3.7| 
-|#.##;(#.##);/z/e/r/o|-3.7|(3.7)| +|#.##;(#.##);\z\e/r\o|-3.7|(3.7)| 
-|#.##;(#.##);/z/e/r/o|0|zero|+|#.##;(#.##);\z\e\r\o|0|zero| 
 + 
 +**AppleScript Usage Note:** the same backslash character is used to escape values in an applescript string, so to use this in AppleScript you need to double backslash the backslash character. For the example above of formatting a temperature value which is “#.#\ \°\F” would work in the various formatting fields but when using in the **format number** verb in AppleScript you would have to enter it like: 
 + 
 +<code> 
 +write log format number 75.621 format “#.#\\ \\°\\F” 
 +</code>
dictionary/more/formatnumber.1464201074.txt.gz · Last modified: 2023/02/13 14:51 (external edit)