Navigation

Data Formatting in DI#

Data formatting in DI# plays a key role in the readability and comprehension of displayed information. By mastering the formats of numbers, dates, monetary values, and percentages, it becomes possible to precisely adapt the data presentation to each context. This article presents formatting options to produce clear, consistent, and professional results in Dialog Insight.


Numbers and Decimals 

Precision and separators of decimals (periods, commas, spaces)

The "N" (Number) format is used to display a number with separators (thousands + decimals). The precision is chosen: "N0", "N2", etc., and ideally, the culture.

[[
int n = 123456789;
decimal x = 1234567.8912;

output.write(n.ToString("N0", "fr-CA")); // "123 456 789"
output.write(n.ToString("N0", "en-CA")); // "123,456,789"

output.write(x.ToString("N2", "fr-CA")); // "1 234 567,89"
output.write(x.ToString("N3", "en-CA")); // "1,234,567.891"
]]

Leading zeros for numerical identifiers

For identifiers, invoice numbers, codes, etc., the "D" (Decimal) format allows you to specify a minimum length for the number.

[[
int id = 842;
output.write(id.ToString("D6")); // "000842"
]]

If the number is the result of a calculation, first assign the calculation to a variable, then call ToString() on that variable.


Date and Time

Default format, short or long, or depending on the culture

For a readable date (e.g., “August 21, 2025”) or a standardized date for export, use an explicit format (and a culture if necessary).

[[
datetime d = 2025.08.21 17:00:00;

output.write(d.ToString());                    // default display (depending on the system)
output.write(d.ToString("D", "fr-CA"));        // long date (culture)
output.write(d.ToString("d", "fr-CA"));        // short date (culture)
output.write(d.ToString("yyyy.MM.dd"));        // stable format (recommanded for exports)
]]

Time with or without the date

Whenever the time component is important (appointment, start of promotion, delivery time), the time part can be explicitly formatted.

[[
datetime d = 2025.08.21 17:00:00;
   
output.write(d.ToString("HH:mm"));             // 17:00
output.write(d.ToString("yyyy.MM.dd HH:mm"));  // 2025.08.21 17:00
]]

Day and month in letters

For a more editorial presentation (e.g., "Thursday, August 21, 2025"), text formats with appropriate cultural context can be used.

[[
datetime d = 2025.08.21 17:00:00;

output.write(d.ToString("dddd dd MMMM yyyy", "fr-CA"); 
]]

Currency and Monetary Values

Symbol or name of the currency

To display a currency symbol or its full name, use one of these methods.

[[
string symbol = System.Tools.Currency.GetSymbol("EUR");       // "€"
string nameEN = System.Tools.Currency.GetName("CAD", "en");   // "canadian dollar"
string nameFR = System.Tools.Currency.GetName("CAD", "fr");   // "dollar canadien"

output.write(symbol);
output.write(nameEN);
output.write(nameFR
]]

Rounded amount

When the amount comes from a calculation (discount, tax, pro rata), it can be rounded and formatted.

[[
decimal raw = 10.0 / 3.0;
decimal rounded = System.Tools.Math.Round(raw, 2);

output.write(rounded.ToString("C2", "en-CA"));
]]

Note: In DI#, Round uses the bank rounding.

Décimals in an amount

For a rendering with symbol and 2 decimal places, you can use "C2" and specify a culture.

[[
decimal amount = 1234.5;

output.write(amount.ToString("C2", "en-CA")); // "$1,234.50"
output.write(amount.ToString("C2", "en-GB")); // "£1,234.50"
output.write(amount.ToString("C2", "fr-CA")); // "1 234,50 $"
]]

Percentage

The "P" format displays a decimal number as a percentage (value × 100) and applies the culture (separators + % symbol). You must use "P0", "P1" or "P2" to choose the number of decimal places.

[[ decimal rate = 0.9876;

output.write(rate.ToString("P1", "en-CA")); // "98.8%";
output.write(rate.ToString("P1", "fr-CA")); // "98,8 %";  
]]

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.