The main data types in 1C - number, boolean and date, can be represented in many formats. Programmers often face the fact that the requirements for the type of data vary greatly in different reports and tables. 1C developers thought about the convenience of programmers and created a special function that greatly facilitates the process of changing the appearance of data. The main task of the function is to convert a number, date, or boolean type to the desired form of a string type.

Description of the "Format" function

The syntax of this function is simple - you can pass two parameters as parameters. First, the developer specifies the value to be formatted. In order for 1C to understand how to change the value, the programmer specifies the second parameter as a string value containing predefined operands. It is the value of this line that determines how users will see the data in the report.

FormattedValue = Format(VariableForFormatting, TextFormatString);

If the "FormatString" parameter is not set, then 1C converts the specified value into a string. Keep in mind that an empty date and 0 will be converted to an empty string, which users may not like. Each parameter in the format string is a combination of the name, the "=" symbol, and the value specified in quotation marks. This allows you to include the characters used in writing the format string of the Format function in 1C.

You can insert any character into the data display except for those used in the format string writing syntax. If there is a need to get around this limitation, use single quotes. This solution will also help in situations where a symbol might be misinterpreted by the compiler.

For the convenience of developers, 1C has a built-in format string constructor. It can be accessed in modules via context menu or in the ACS through the places provided by the developers. For example, such an opportunity can be found in the list of fields for the request in the "Design" section.

The most important advantage of the constructor is that you can immediately see how your data will look like in the end. After you have posted necessary settings for a specific data type in the "Example" section, you are shown the result of your settings. In the unnamed text box at the bottom, you'll find the format string used to get the result. It can be copied and used in the future if the result suits you completely.

The format string constructor can be a great help for novice developers, but experienced programmers prefer not to waste time on it. Development will go much faster if you know the basic key parameters of the format string and use them without calling the constructor.

Basic format string options

Learning all available commands will not work, and this is not necessary. The developer only needs to know some popular operations and how to apply them. At any time, you can open the full list of format string parameters in the syntax assistant and select the one you need. The following parameters can be useful to a 1C programmer in daily work:

  • L is the format of the country for whose representatives the data will be displayed;
  • ChG - sets the grouping of the digits of the number;
  • FZ - sets the total number of groups of characters of the integer and fractional parts of the number that will be displayed. If the value of the NPV parameter is not specified in the format string with this key, then the fractional part will not be shown;
  • FDC is a parameter that specifies the number of characters in the part of the number after the decimal point. Rounding occurs according to the standard rules of mathematics;
  • CHS is a parameter that shifts the digits of a number. The value can be positive - multiplying by 10, or negative - dividing. Useful command, if you need to output in one form, and continue working with a number in another;
  • FRD - sets the symbol that separates the fractional and integer parts of the number. To set the character that separates groups of an integer part, use "CHG". To use a non-breaking space, use an empty string;
  • FHN - shows the use of leading zeros. The value of this parameter is not set;
  • DF is one of the most common format string options. Controls the date format. In 1C, using the "Format" command, you can display the date in almost any format, including writing the name of the month. Possible values a lot, their list can be seen in the syntax assistant;
  • BL and BI - set the representation for the logical data type, answering, respectively, for false and true. Thus, you can replace the standard “tick” with any word or phrase that is more intelligible to users.

The universalism and convenience of the constructor have become the key reasons for the popularity of the "Format" function among 1C developers. Flexible settings will help you set any appearance data at the request of the client.

Detailed description. Click to expand

Format string is a string value that includes formatting options.

Formatting options are listed through the symbol ";". The presence of the parameter means that the formatting is different from the standard one.

If the parameter is not specified, then standard formatting is applied, which basically corresponds to converting the value to a string. However, for values ​​of type Number and Date, the default values ​​(0 and 01.01.0001 00:00:00 respectively) will return an empty string.

Each parameter is specified by the parameter name, the “=” symbol, and the parameter value. The parameter value can be specified in single or double quotes. This is required if the parameter value contains characters used in the format string syntax.

Arbitrary characters can be specified inside the parameter value, which will be displayed as is when forming the resulting string. Thus, for example, you can specify the separators for hours, minutes, and seconds when formatting time. If these characters match format string values, they must be enclosed in single quotes.

Names and values ​​of format string parameters:

  • L - the name of the language, country for which standard formatting will be performed.
  • CHC - total number displayed decimal places of integer and fractional parts. The original number is then rounded in accordance with the rounding rules. If this parameter is specified, then to display the fractional part of the number, the NPV parameter must be specified, otherwise the fractional part will not be displayed.
  • NDC - the number of decimal places in the fractional part. The original number is then rounded in accordance with the rounding rules.
  • CHS - bit shift: positive - division, negative - multiplication. In other words, this means that the original number will be multiplied or divided by 10*C, where C is the modulo value of the parameter.
  • FRD is the symbol-separator of the integer and fractional parts.
  • CHRG - a character-separator of groups of the integer part of the number. If an empty string is used as a delimiter, then the delimiter will be a non-breaking space character.
  • CH is a string representing zero value numbers. If not set, the representation is an empty string. If “PN=” is set, then in the form “0”. Not used for numeric input fields.
  • FHN - whether to output leading zeros. The value of this parameter is not set, the actual presence of the parameter determines the output of leading zeros.
  • CHG - the order of grouping the digits of the number. As a value, numbers are indicated, separated by commas, indicating the number of grouped digits from right to left. Only the first two numbers make sense. The first of these indicates the primary grouping, that is, the one that will be used for the least significant digits of the integer part of the number. If the second number is not specified, then only the least significant digits will be grouped. If 0 is specified as the second number, then the value specified for the primary grouping will be applied to all digits of the integer part of the number. If a value other than 0 is used as the second number, then this value will be used to group all digits, except for the least significant ones already grouped.
  • CHO is a representation of negative numbers.
    • 0 (0) – string like “(1,1)”;
    • 1 (1) – string like “-1,1”;
    • 2 (2) – string like “- 1.1”;
    • 3 (3) – string like “1,1-“;
    • 4 (4) – string like “1,1 -“.
  • DF is the date format.
    • e – day of the month (in digits) without leading zero;
    • dd – day of the month (in digits) with a leading zero;
    • dd is the short name of the day of the week;
    • dddd - full name of the day of the week;
    • М – month number (in digits) without leading zero;
    • MM – month number (in digits) with a leading zero;
    • MMM - short name of the month;
    • MMMM is the full name of the month;
    • k - the number of the quarter in the year;
    • d – year number without century and leading zero;
    • yy – year number without century with leading zero;
    • yyyy - year number with century;
    • h - hour in 12-hour version without leading zeros;
    • hh - hour in 12-hour version with a leading zero;
    • H – hour in 24-hour version without leading zeros;
    • HH (HH) - hour in 24-hour version with a leading zero;
    • m – minute without leading zero;
    • mm – minute with leading zero;
    • s – second without leading zero;
    • ss - second with leading zero;
    • bb - Displays the AM/PM half day (valid only for configuration languages ​​that support 12 hour time representation).
  • DLF is the local date format. Specifies the option to display parts of the date.
    • D - date (in numbers);
    • DD - long date (month in words);
    • B - full time, date can be combined with time;
    • DV - date time.
  • DP is a string representing an empty date (for example, Format('00010101000000' ,DP=””empty date”””) would return the string “empty date”).
  • BL is a string representing boolean Lie.
  • BI - a string representing a boolean value True.

Programming (and business programs) usually deal with the following simple data types: number, string, date. The values ​​of these types for different countries, standards and just habits can have a different idea.

Probably the most famous example is the different representation of time - in Russia it is customary to use 9:00 and 21:00, and in English-speaking countries 9am and 9pm. The difference is both in logic (12-hour system or 24-hour system) and in writing.

The value representation is called "format" and today we will discuss changing the date format and number format in 1C.
Formatting can be used both by a programmer in the 1C language, and visually, without programming, for example, when creating a printable form or report, when setting up elements on a form.

What is formatting

The number and date, regardless of its representation on the screen or on print, remains itself. Formatting means only conversion to a string value - that is, how it will “look” on a computer screen or on paper.

The main differences between 1C formats for representing numbers and dates:

  • Number
    o "." or "," to separate the fractional part
    o number of decimal places
    o grouping digits in 3's (1,000,000, not 1,000,000)
  • date and time
    o year, month, day order
    o delimiter character
    o 1C time format (12 or 24 hours)
    o spelling details.

Also, in the 1C format, additional “conveniences” can be indicated, for example, display negative numbers in red, or the representation of an “empty value” in the form of “0” or “not filled”.

Formatting principle

The default formatting works, for example, when converting a number to a string. In some cases, such settings can serve a disservice where the programmer does not expect it.

For example, when converting a number to a string, it is translated taking into account the grouping of digits (and you expect this?):
StringNumber = AbbrLp(2400); //will be equal to "2 400"

To accurately specify the format in the 1C language, there is a Format () function, with which it is possible to specify the required representation.
NumberString = Format(2400, "Settings")

As the line "Settings" you need to specify the required format 1C. Such settings are specified in a special coded form. Consider the most commonly used settings:

Format 1С date and number by default

If you need to display a date or number and don't want to bother with knowing how they should be represented according to the rules of the desired country, there is a simple setting that will allow you to do this:

L = ShortName of the Desired Country

An example of displaying a date according to the rules of some countries:
Format(CurrentDate(), "L=ru")
> 28.03.2012 14:21:32

Format(CurrentDate(), "L=en")
> 3/28/2012 2:21:24 PM

Format(CurrentDate(), "L=fr")
> 28/03/2012 14:22:08

As it is not difficult to see, the names of countries are intuitive.

Date format in 1C language

If the default setting is not enough for you and you would like to specify the order of the parts of the date and the symbols for their separation, you must use the setting:
DF = "dmg hms"

Accordingly, "dmg" is the day, month and year, and "hms" is hours, minutes and seconds. Any of these parts can be skipped. The order is any. The characters specified between the parts will be used as separator characters.

The character of a part of the date can be specified several times in a row, the appearance of this part of the date depends on this, for example, "d" or "dd" or "dddd".

Deciphering parts of the date:

  • d - day
    o small "d"
  • M - month
    o big "M"
    o can be specified from 1 to 4 times
  • d - year
    o small "g"
    o can be listed 1 or 2 or 4 times
  • h - hours
    o small "h" - 12 hour format
    o big "H" - 24 hour format
  • m - minutes
    o small "m"
    o can be specified 1 or 2 times
  • s - seconds
    o small "s"
    o can be specified 1 or 2 times
  • bb - AM/PM display for 12 hour format
  • k - quarter.

An example of displaying a date with rules:
Format(CurrentDate(), "DF=""dd.MM.yyyy hh:mm:ss""")
> 28.03.2012 02:44:44

Format(CurrentDate(), "DF="" M / d /yyy h:m:s dd""")
> 3/28/2012 2:44:44 PM

Format(CurrentDate(), "DF=""dd/MM/yyyy hh:mm:ss""")
> 28/03/2012 02:44:44

Number format in 1C language
Unlike date formatting, where everything is quite simple, there are many options for number formatting. We will consider those that we found useful - that is, in our opinion, they are often used.

The first "problem" is related to the default grouping of digits in numbers of 3 and separating the groups with a space, for example:
StrNumber = String(22300500)
> 22 300 500

This is inconvenient when a number is converted to a string not for a beautiful and understandable output to the user, but for service needs. This can be influenced by the "CH" parameter, for example:

Format(22300500, "HH=100")
>22300500 //removed zeros altogether

Format(22300500, "HH=6")
> 22 300500 //made a grouping of only millions

A parameter that allows you to round the number when outputting to the required number of digits after the decimal point "NPV":

Format(3.535353, "NPV=""2""")
> 3,54

Parameter that allows you to specify the separator character for the integer and fractional parts of the "BRD":

Format(3.535353, "BRD="".""")
> 3.535353

For some cases, it can be useful to be able to display something else instead of the number "0": an empty string or "not filled". This allows you to make the "CHN" parameter:

Format(0, "HN=""""")
>

Format 1C fields on the form

We have discussed with you the techniques that allow the programmer to format the value in the 1C language. There are also mechanisms that allow you to specify the required format visually, without programming.

For example, the user works with the form. The form has a field that displays the date. We can influence the representation of this date.

Open the properties of this field. To do this, in the thick client, click right click on the field, and in the thin one - right-click on the field name in the field list, select Properties.
The field has a "Format" property.

Click the "…" button to set it up. To set up the date format, use the Date tab (for a number, use the Number tab). You can select the required format from the list.

Format 1C cells in printed form

When you need to design a printed form (report or document printing), you can assign a cell format in exactly the same way as for a document field.
We select a cell (or several cells at the same time), go to the properties, the "Format" property, select the required format.

Format 1C in SKD

ACS reports allow you to customize the 1C format for both the programmer (at the time of creating the report) and the user (when using the report). There are also more opportunities through the use of conditional formatting.

This means you not only specify which field to format, but also under what condition (for example, if the value of this field is negative).

In the Enterprise mode, select the menu item on the report form "Change variant". In the ACS report in the thick client, this item is in the "Actions/Settings" menu.

In the opened form of all ACS settings there is a tab "Conditional formatting". Add a new line. The line has three columns:

  • Decor. Specify the required 1C format - font, background or text color, 1C format for displaying numbers and dates
  • Condition. If this design is always used, then leave this field blank. Otherwise, specify the field and its value. Then formatting will be applied only in those lines in which these values ​​match. If you need to specify the values ​​of several fields at the same time and the "and/or" conditions, add a group and group the fields using groups.
  • Formed fields. List of fields for which formatting will be applied.

1C format in managed forms

The same formatting rules apply to any managed tenant list form. In the list form, select the menu item "All actions / Configure list".

The Conditional Formatting tab.

Select the desired design and format.

Specify the list of fields to which this design will be applied.

Options:

<Значение>

The value to be formatted.

<ФорматнаяСтрока>

The format string is a string value that includes formatting options.

Formatting options are listed through the ";" character. The presence of the parameter means that the formatting is different from the standard one.

If the parameter is not specified, then standard formatting is applied, which basically corresponds to converting the value to a string. However, for values ​​of type Number and Date, the default values ​​(0 and 01.01.0001 00:00:00 respectively) will return an empty string.

Each parameter is specified by the parameter name, the "=" symbol, and the parameter value. The parameter value can be specified in single or double quotes. This is required if the parameter value contains characters used in the format string syntax.

Arbitrary characters can be specified inside the parameter value, which will be displayed as is when forming the resulting string. Thus, for example, you can specify the separators for hours, minutes, and seconds when formatting time. If these characters match format string values, they must be enclosed in single quotes.

Names and values ​​of format string parameters:

  • L - the name of the language, country for which standard formatting will be performed.
  • CC - the total number of displayed decimal places of the integer and fractional parts. The original number is then rounded in accordance with the rounding rules. If this parameter is specified, then to display the fractional part of the number, the NPV parameter must be specified, otherwise the fractional part will not be displayed.
  • NDC - the number of decimal places in the fractional part. The original number is then rounded in accordance with the rounding rules.
  • CHS - bit shift: positive - division, negative - multiplication. In other words, this means that the original number will be multiplied or divided by 10*C, where C is the modulo value of the parameter.
  • FRD - the symbol-separator of the integer and fractional parts.
  • CHRG - character-separator of groups of the integer part of the number. If an empty string is used as a delimiter, then the delimiter will be a non-breaking space character.
  • CHN - a string representing the zero value of a number. If not set, the representation is an empty string. If "HN=" is specified, then in the form of "0". Not used for numeric input fields.
  • FHN - whether to output leading zeros. The value of this parameter is not set, the actual presence of the parameter determines the output of leading zeros.
  • ChG - the order of grouping the digits of the number. As a value, numbers are indicated, separated by commas, indicating the number of grouped digits from right to left. Only the first two numbers make sense. The first of these indicates the primary grouping, that is, the one that will be used for the least significant digits of the integer part of the number. If the second number is not specified, then only the least significant digits will be grouped. If 0 is specified as the second number, then the value specified for the primary grouping will be applied to all digits of the integer part of the number. If a value other than 0 is used as the second number, then this value will be used to group all digits, except for the least significant ones already grouped.
  • CHO - representation of negative numbers.
    • 0 (0) - string like "(1,1)";
    • 1 (1) - a string like "-1,1";
    • 2 (2) - a string like "- 1,1";
    • 3 (3) - a string like "1,1-";
    • 4 (4) - a string like "1,1 -".
  • DF - date format.
    • d - day of the month (in digits) without leading zero;
    • dd - day of the month (in digits) with a leading zero;
    • ddd - short name of the day of the week;
    • dddd - full name of the day of the week;
    • M - month number (in digits) without leading zero;
    • MM - month number (in digits) with a leading zero;
    • MMM - short name of the month;
    • MMMM - the full name of the month;
    • k is the number of the quarter in the year;
    • d - year number without century and leading zero;
    • yy - year number without century with leading zero;
    • yyyy - year number with century;
    • h - hour in 12 hour version without leading zeros;
    • hh - hour in 12 hour version with leading zero;
    • H - hour in 24-hour version without leading zeros;
    • HH (HH) - hour in 24 hour version with leading zero;
    • m - minute without leading zero;
    • mm - minute with leading zero;
    • s - second without leading zero;
    • ss - second with leading zero;
    • вв - display half of the day AM/PM (valid only for configuration languages ​​that support 12-hour time representation).
  • DLF - local date format. Specifies the option to display parts of the date.
    • D - date (in numbers);
    • DD - long date (month in words);
    • B - full time, date can be combined with time;
    • DV - date time.
  • DP is a string representing an empty date (for example, Format("00010101000000" ,"DP=""empty date""") would return the string "empty date").
  • BL - a string representing a boolean value Lie.
  • BI - a string representing a boolean value True.