Hi, Readers.
Today I would like to share another mini tip about Business Central, how to display the decimal value as a percentage.
I saw this question on the forum this morning.
percentage field ā Dynamics 365 Business Central Forum Community Forum
There are actually two solutions to this.
1. As with the Microsoft standard, just adding % to the caption.
For example, on the Job Card (88, Document) page:
Source Code:
So we can imitate it quite simply, but please note that we need to recalculate it when using it, divide it by 100.
2. Setting the AutoFormatExpression property
Set to the property according to the following syntax: '[SubType][,<currencycode or expression>[,<PrefixedText>]]'
SubType
Ā can beĀ 1
,Ā 2
, another number, or omitted: 1
Ā sets the value to an amount type (see 1 above).Ā 2
Ā sets the value to a unit amount type (see 2 above).
The syntax for these two settings is: 'SubType,<currencycode[,<PrefixedText>]'
If you omit the subtype or use a number other than 1 or 2, the syntax is: '<CustomNumber>, <expression>[,<PrefixedText>]'
whereĀ <expression>
Ā sets the precision and one of the standard formats. For more information, seeĀ Standard Formats.
If you want to display the decimal value as a percentage, then you can addĀ %
Ā at the end of the setting. For example:
AutoFormatType = 10;
AutoFormatExpression = '<precision, 1:1><standard format,0>%'
When you include aĀ %
Ā at the end of the setting, then the decimal value is assumed to be the ratio, and the decimal value will be multiplied by 100. For example, a value of 0.98 will be formatted toĀ 98%.
Letās see a simple example,
Enter 0.1234
Display 12.34%
Source Code:
tableextension 50111 MyExtension extends Item
{
fields
{
field(50100; "Expected Profit"; Decimal)
{
Caption = 'Expected Profit';
AutoFormatType = 10;
AutoFormatExpression = '<precision, 2:4><standard format,0>%';
}
}
}
pageextension 50111 MyExtension extends "Item Card"
{
layout
{
addafter("Item Category Code")
{
field("Expected Profit"; Rec."Expected Profit")
{
ApplicationArea = All;
}
}
}
}
PS: The number of decimal places that can be entered is determined by <precision, 2:4>
END
Hope this will help.
Thanks for reading.
ZHU
ć³ć”ć³ć