Hi folks,
I welcome you to see some awesome examples of the FORMAT AND DELCHR function, and how it helps a lot to format any value to a string, to remove some special characters, some string, or characters, remove the comma from the decimal, remove all alphabets, keep digits only, keep only special characters, and many more syntaxes.
But in this article, I will explain what are the different ways to remove the comma from the decimal field or variable while displaying in the message or while creating a CSV file.
Way 1: Remove comma from decimal
Needed: Suppose a variable or field called Amount and value is 1,230 and you want digits only.
Syntax: Message(Format(Amount, 0, 1));
Explanation: It will create text string from the decimal without a thousand separators (Standard Format 1), you can also assign the formatted result to any text string
-> e.g. textString:=Format(Amount,0,1);
The best part of this syntax is this remove
Code:
Result:
Other Ways: Remove comma from decimal
Code Snippet Screenshot:
Code in text format:
// Other ways to remove the comma from Decimal
pageextension 50101 CustomeList extends "Customer List"
{
trigger OnOpenPage()
var
recGLEntry: Record "G/L Entry";
buidlResultString: Text;
begin
if recGLEntry.FindFirst() then begin
buidlResultString := 'Original Amount => \' + Format(recGLEntry.Amount);
buidlResultString += '\\Syntax: Format(Amount,0,1) \Output: ' + Format(recGLEntry.Amount, 0, 1);
buidlResultString += '\\Syntax: DELCHR(Format(recGLEntry.Amount), "=",",") \Output: ' + DELCHR(Format(recGLEntry.Amount), '=', ',');
buidlResultString += '\\Syntax: DELCHR(FORMAT(recGLEntry.Amount),"<=>",",") \Output: ' + DELCHR(FORMAT(recGLEntry.Amount), '<=>', ',');
buidlResultString += '\\Syntax: FORMAT(recGLEntry.Amount, 0, "<Sign><Integer><Decimals><Comma,.>") \Output: '
+ FORMAT(recGLEntry.Amount, 0, '<Sign><Integer><Decimals><Comma,.>');
buidlResultString += '\\Note: in syntax replace double quote with single quote.';
Message(buidlResultString);
end;
end;
}
Output:
Done!
I hope this article is helpful for you NAV/Business Central folks.
Stay Tuned!