Number - Int & Float
TreeGrid documentation
Int type shows integer number in selected format.
Float type show floating point number in selected format.
The only difference between the types is that the
Int type does not accept the decimal separator and exponent characters while editing.
In the input / output XML is the
Float type always in English notation with
dot as floating point separator.
Format
<C> <cell> string
Type
["Text"] Type = "Int" or "Float"
To define Int type, set column or cell attribute Type to "
Int", for Float type set Type to "
Float".
new 6.0 chg 12.0 <C> <cell> bool
CanEmpty
[0/1]
If the cell number value differ between 0 and "".
Remember the default value is 0, except in Filter row.
If set to
0, the empty input value is always converted to 0. So the cell never contains (empty) string value.
It is good to set it to
0 when the numbers are sources for a Formula.
Since 12.0 the default value for Filter row is 1.
new 6.0 <C> <cell> string
EmptyValue
[""]
The string displayed when the date value is entered as empty string.
The cell can contain empty value only if
CanEmpty is 1.
It is shown only for display, not for edit.
It is
not escaped, it can contain HTML code.
chg 7.0 <C> <cell> string
Format
Specifies number string format - how the number will be displayed.
This format string uses almost the same formatting as Microsoft .NET System.DateTime.
ToString (string format) function.
Empty format
If the
Format is not set or is empty (default), the default English format is used with a
dot as floating point separator.
Standard format
Standard format is
one letter format. This format loads user format from file
Text.xml, tag <
Format>, attributes "
n.."
"g" | General | (ng = "0.######" , ngg = "0.###### E+00"), for numbers under 1e10 uses ng, above uses ngg. |
"f" | Fixed | (nf = "0.00") |
"c" | Currency | (nc = "$###########0.00") |
"p" | Percent | (np = "0.00%") |
"r" | Rounded | (nr = "0.0000", nrg = "0.0000 E+00"), for numbers under 1e10 uses nr, above uses nrg. |
"e" | Scientific | (ne = "0.000000 E+000") |
User format
User format can contain any characters but only few have special meaning and the others are written into output without any change.
Since 6.2 version if there no '0' and '#' in format string, no number is shown, only the format string.
There can be maximally 20 digits (0 and #) shown before and after decimal point. Note, JavaScript has maximally 17 digits precision.
0 | Place for a digit, displays digit or 0. If there are more digits than count of 0 and # in integer part, all the rest digits are written left to the first 0 or #. |
# | Place for a digit, displays digit or nothing if there are no more digits. Has sense only for decimal part or exponent definition. |
? | (new 13.0) Place for a digit, displays digit or empty space if there are no more digits. Has sense only for decimal part. |
8 |
(new 7.0) Hidden digit, the digit will not be displayed. Digits are always counted from decimal separator position to both sides.
It cannot be combined with '#' in the same number part. It can be used only for left and right side of integer part or left side of decimal part.
Example: Val = "123456.789", Format = "8000" => Result = "456"; Format = "088" => Result = "1234"; Format = "8.80" => Result = "8"
|
. |
(Dot) Decimal separator. Displays decimal separator defined in file Text.xml, tag <Format>, attribute DecimalSeparator. (dot by default).
Can be only used only once.
|
, |
(Comma) This character has two meanings:
If this is placed between any digits characters ('0' or '#') left to decimal separator, there will all three digits separated by thousand separator defined in file Text.xml, tag <Format>, attribute GroupSeparator. (comma by default).
Example: Val = "123456.789", Format = ",0.00" => Result = "123,456.79"
(since 10.0) It is possible to specify different number of separated digits than 3 by <Format> attributes GroupCount1 (the last group) and GroupCount (other groups).
For example for Indian number format set <Format GroupCount1='3' GroupCount='2'/>
If this is placed between last digit and decimal separator (or to the end if decimal separator is not used), the value will be divided by 1000. There can be more commas to divide more times.
Example: Val = "123456.789", Format = "0,,.00" => Result = "0.12"
|
% |
Place for '%' character (it is defined in file Text.xml, tag <Format>, attribute Percent). If it is present, the number is also multiplied by 100.
To place the % character without multiplying by 100, write it with backslash "\%".
|
E, e, E-, E+, e-, e+ |
Result will use exponential notation. To this location is placed 'E' or 'e' letter followed by digits of exponent.
|
|
If used exponential notation, the number of digits before decimal separator is given by count of all digit places ('0' or '#') before decimal separator.
This letter must be followed by number digit places ('0' or '#') to specify number of exponent digits.
E or e specifies case of E letter, E+ uses sign + for positive exponents, E- and E uses no sign for positive exponents.
Example: Val = "123456.789", Format = "000.000 E+00" => Result = "123.456 E+03"
Example: Val = "-0.0123456789", Format = ":0.0000(E000)" => Result = ":-1.2346(E-002)"
|
; |
(Semicolon) Separates formats used according to the value size and type.
There can be up to four default formats without condition and next more conditional formats. The conditional formats should be placed before default formats.
1st default format is used for positive numbers (and for 0 if the third format missing).
2nd default format is used for negative numbers (without minus sign).
Remember, from the negative part is read only string before number and after the number, all other (the number format) is used always from positive part.
So the negative part can be used only to remove, replace or change position of the minus or change CSS attribute like color by the prefix and postfix.
3rd default format is used for 0.
4th default format since 13.0 is used for text (in Auto type only). It can contain character @ to place actual text value here.
If it does not contain the @, the actual value is not displayed.
If the 4th format is missing, the Auto type displays the text value as is.
If the 2nd or 3rd format contains the character @ it is automatically used for the text value and not for negative or zero values.
|
[color] |
(new 13.0) Colors the whole part (parts are separated by semicolon) in given CSS color.
|
[condition] |
(new 13.0) Uses given part (parts are separated by semicolon) only if the value fulfills the condition.
Condition can be: [=value], [<>value], [<value], [<=value], [>value], [>=value].
|
_ |
(new 13.0) (Underscore) Places space as wide as the next character after the "_". The next character is not printed.
|
\ |
(Backslash) Escape character, the next character is placed to output without any changes. Use to place format characters as 0 # . , E e + - \ " ' %.
|
'xxx' or "xxx" |
Characters in quotes or double quotes are placed to output without any changes. Use to place format characters as 0 # . , E e + - \ " ' %.
|
For example:
Format='$0.00' => "$0.10" or "$12.54"
Format=' #.00##;<span style=\'color:red\;\'>#.00##</span>;nothing' => negative numbers in red, 0 as nothing
If you want add
HTML tags before and after value, use rather cell attributes
HtmlPrefix and
HtmlPostfix instead of
Format.
If you really need to place
HTML tags into output (for example to use different HTML tags for positive and negative numbers), set
<Cfg NoFormatEscape='1'>. The HTML tags can be set in
Format only,
not in
EditFormat.
upd 6.0 <C> <cell> string
EditFormat
Format string to display the number for editing. It does
not affect the input format of the numbers.
<C> <cell> string
ExportFormat
A number format to export to Excel. Used only
for Export_Type = 0.
It is specific Excel number to export the number in specific format.
If you don't know the format for the cell, create xls file with one cell, specify its format you want and save it as one file web page (mht file).
Open this mht file and search style property "mso-number-format" and its value set to the ExportFormat.
The standard values are "
Fixed" for 0.00 or "
Scientific".
The format string is similar to TreeGrid number format, but with escaped all not number and not digit characters by backslash.
Here are some sample formats:
"0\.00" displays two required decimal digits,
"0\.#\#" displays maximally two decimal digits,
"\#\,\#\#0\.0000" separates every 3 digits by ',' and shows decimal 4 digits.
chg 6.0 <C> <cell> bool
NoFormatEscape
[1]
If set to "", it means
0 for text and
1 for number and date.
If set to
0, the Format is escaped, so the characters & and < are displayed as they are.
If set to
1, you can use HTML tags in columns
Format string, in prefix and postfix for text and anywhere for numbers.
new 13.0 <Cfg> int
RoundNumbers
[0]
If all numbers (Float and Int types) in grid will be rounded to
RoundNumbersDigits, bit array.
1. bit &
1 - Rounds all numbers in cells without
Format.
2. bit &
2 - Rounds all numbers in cells with
Format. Before the number is formatted.
3. bit &
4 - If set, rounds to
RoundNumbersDigits all digits, otherwise rounds only decimal digits.
new 13.0 <Cfg> int
RoundNumbers
[5]
Number of decimal digits to round numbers by
RoundNumbers. Can be also negative.
global func. string
NumberToString
(Number num, string format)
Converts number to string according to format string as in function ToString() in C#.NET.
global func. Number
StringToNumber
(string str, string format)
Converts string to number
Localization
The default number format and setting are specified in
Text.xml, in <
Lang><
Format /></
Lang> tag.
The default settings is for
English language, changing the
Format tag attributes you can easily localize it to another language.
new 12.0 <Format> bool
BaseSeparators
[0]
Controls Int, Float and Date types conversions to string without explicit format string set.
If set to
1, it always uses standard U.S. English decimal, date and time separators and also date order M/d/yyyy.
If set to
0, it uses actual
DecimalSeparator,
DateSeparator and
TimeSeparator
and date format is chosed according to the date separator as "M/d/yyyy" or "d.M.yyyy" or "yyyy-M-d".
Prior to 12.0 the default value and behavior was 1, since 12.0 was changed to 0!
<Format> string
DecimalSeparator
[.]
The string displayed as floating point separator.
You can set it also dynamically by API according to browser's locale by such code:
Grids.OnLoaded = function(G){ G.Lang.Format.DecimalSeparator = Number(1.5).toLocaleString().charAt(1); }
new 6.0 <Format> char[ ]
InputDecimalSeparators
[.,]
The characters permitted to input as decimal separator.
<Format> string
GroupSeparator
[,]
The string displayed as thousands separator.
new 6.0 <Format> char[ ]
InputGroupSeparators
[ ]
The characters permitted to input as group separator.
Now it should be empty because it is not permitted to input numbers with group separator.
<Format> string
Percent
[%]
The string displayed as percentage character.
<Format> string
NaN
[NaN]
String displayed for incorrect number - Not A Number.
new 12.0 <Format> int
Digits
[]
First character separated array of 10 digits strings to replace the standard digits 0 - 10.
Useful to display Arabic digits instead of standard digits by such definition:
<Lang><Format Digits="|٠|١|٢|٣|٤|٥|٦|٧|٨|٩"/></Lang>
It replaces all digits in all cells, regardless of the cell type!
new 12.0 <C> <cell> int
Digits
[]
Digits to replace for this cell or column.
Used only if some <Format Digits> are defined.
Set it to empty string to not use the <Format
Digits>