Follow

ToString()

Almost every variables (that are not already strings!) can have .ToString() applied to them to convert them to strings “the way you want them to”. Of course, any time you output a variable, example:[[=Contact.f_Birthday;]], this gets converted to text. We have some default conversions, but they’re not always appropriate (for instance, a decimal value will output a lot of zeroes, which does not look too good on an account statement). When you append .ToString(“…”) on a value, the parameter that you pass to the function is passed directly to the .ToString() method of the basic .NET datatype involved. So Order.InvoiceTotal.ToString(…) actually executes.NET’s decimal.ToString(…) method.

 

This means .ToString() supports all format strings that are available in .NET. You can visit the MSDN document site for the full reference, a good starting point is this:

 

1 Comments

  • Avatar
    Vyacheslav KONOVALOV

    Example:

    When you have a field of type Decimal, Currency or Money (with a floating point) and you need to hide the numbers after the comma (,0000) in your messages (show 1234 or 1234,00 instead of 1234,0000), you can use the following syntax. 

    If you have a field named Item.Price which you want to format, the syntax would be the following:

    [[=Item.Price.ToString("0,00");]]  -> will show 1234,00

    [[=Item.Price.ToString("0)"];]]  -> will show 1234

    [[=Item.Price.ToString("# ###");]] -> will show 1 234 (with a space between '1' and '2')

Please sign in to leave a comment.