Localise numbers

In this tutorial, we show you how to specify separator characters used when formatting numbers.

Before starting this tutorial you should create a new app with a bladeset and a single blade.

Create a Number

We will be using the workbench generated for a newly created blade for this example. Let’s get a simple Number object into our blade.

test.blades.mytestblade.ExampleClass = function()
    var sMessage = caplin.i18n.Translator.getTranslator().formatNumber(4012.5);
    this.message = new caplin.presenter.property.Property(sMessage);

Refreshing your workbench should now show the number as the message.

Specify Separator Characters

Use these properties in your i18n file at $APP_ROOT/resources/i18n/en/en.properties:

Property Description Example
ct.i18n.decimal.radix.character=. Decimal radix character 4.2
ct.i18n.number.grouping.separator=, Number grouping separator 3,000,000

If you use the settings in the table, then the example will now look like this, with a comma separating the thousands, and the decimal separator is a dot (or" "period" if you prefer).

i18n number