Numeric (money) formatting in Vala

Hello all,

I am new to Vala and I am struggling with how to format a float value to a currency/monetary format.

I have tried the following:

public string format_to_monetary_form(float value, string currency) {
        Intl.setlocale (LocaleCategory.NUMERIC, "");
        string pattern = "%'.2f %s";
        return pattern.printf(value, currency);
}

calling the function format_to_monetary_form(10000, "USD"), I expect the following:

10,000 USD

but I get the following instead:

10000 USD

Please kindly assist.

Thanks.

Environment:
Windows 10 (Msys2-MINGW64)

Pls reference libc fprintf's format option, its same as Vala’s format option.

GLib.FileStream.printf — glib-2.0 — Valadoc

Thanks @taozuhong . I’ll give it a try.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.