Sets the format of integers and floating point numbers generated by math operations.

SetFormat, NumberType, Format |

**Parameters**

NumberType |
Must be either INTEGER or FLOAT. |

Format | For For
Padding: If |

**Remarks**

If this command is not used in a script, integers default to decimal format, and floating point numbers default to *TotalWidth.DecimalPlaces* = 0.6. Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).

You can determine whether a variable contains a numeric value by using "if var is number/integer/float"

A variable containing a number can be forced into a new format (as set by this command) by adding zero to it, e.g. Var += 0 or Var += 0.0

The built-in variable **A_FormatInteger** contains the current integer format (H or D). **A_FormatFloat** contains the current floating point format.

To pad an integer with zeros or spaces without having to use floating point math on it, follow this example:

Var := " " . Var ; The quotes contain 10 spaces. To pad with zeros, substitute zeros for the spaces. StringRight, Var, Var, 10 ; This pads the number inVarwith enough spaces to make its total width 10 characters.

__Floating Point Format__

Since AutoHotkey stores all variables as strings, the stored precision of floating point numbers is determined by *DecimalPlaces*. In other words, once a variable is rounded off, the extra precision is lost and cannot be reclaimed without redoing the calculation using a higher value of *DecimalPlaces*.

Any leading or trailing spaces (i.e. padding) in a floating point value will be lost if that value is explicitly assigned to another variable. Use AutoTrim to prevent this.

For the current float format to take effect in a math operation such as addition, at least one of the inputs must contain a decimal point.

A variable containing an integer can be "converted" into a floating point number by adding 0.0 to it, e.g. Var += 0.0. However, if the current float format specifies no *DecimalPlaces*, use this instead:

if Var is integer

Var = %Var%.0

__Hexadecimal Format__

Hexadecimal numbers all start with the prefix 0x (e.g. 0xA9). They can be used anywhere a numerical value is expected. For example, *Sleep 0xFF* is equivalent to *Sleep 255* regardless of the current integer format set by SetFormat.

To convert an integer from decimal to hexadecimal, use this example (the converse can be used to convert in the opposite direction):

SetFormat, integer, hex

VariableContainingAnInteger += 0

SetFormat, integer, d

**Related**

Expression assignment (:=), EnvAdd, EnvSub, EnvMult, EnvDiv, AutoTrim, if var is type

**Example**

Var = 11.333333 SetFormat, float, 6.2 Var -= 1 ; Sets Var to be 10.33 with one leading space because the total width is 6. SetFormat, float, 0.2 Var += 1 ; Sets Var to be 11.33 with no leading spaces. SetFormat, float, 06.0 Var += 0 ; Sets Var to be 000012 SetFormat, integer, hex Var += 0 ; Sets Var to be 0xc SetFormat, integer, d