Forum Discussion

Raghukatta's avatar
Raghukatta
Contributor
7 years ago
Solved

FloatToStr in different counties for check points

Hi,

 

I am working on desktop application which runs in different countries.I need to verify % values with a check points.

For example if the value in US is 4.00% then in German it should be 4,00%.(I need to check % values multiple times like 4.17%,3.56% etc)

I used below code aqString.Concat(FloatToStr("4.00"),"%").This is converting value by country local but it is not showing in decimal value.The result of above function is 4% instead of 4.00% or 4,00%

There is another function aqString.Concat(FloatToStrF(4.00,2,2,2),"%") but this is going to deprecated.

Is there anyway we can override number digits after decimal point for "FloatToStr" function?

 

I found another alternative which is 

Using aqString.Format and setting the local format using below code as aqString.Format is not converting as per local settings.If I use aqString.Format the results in 4.00% in all countries. 

SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ",");

If I use this do I need set local value before checking every % value?

 

Thanks in advance for all your replies. 

  • Hi Raghukatta,

     

    You can use the .NET String.Format method to format numbers according to the current locale:

    dotNET.System.String.Format("{0:F2}%", 4).OleValue

    This returns 4.00% on the US locale and 4,00% on the German locale. The format string {0:F2}% means "format the method's only argument (0:) as a floating-point number with 2 decimal digits (F2) and append % at the end."

     

    If you run tests on one locale but need to format text for another locale, you can specify the locale as a parameter:

    var number = 4;
    var culture = dotNET.System_Globalization.CultureInfo.zctor("de-de");
    var str = dotNET.System.String.Format_3(culture, "{0:F2}%", number).OleValue;

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Raghukatta,

     

    You can use the .NET String.Format method to format numbers according to the current locale:

    dotNET.System.String.Format("{0:F2}%", 4).OleValue

    This returns 4.00% on the US locale and 4,00% on the German locale. The format string {0:F2}% means "format the method's only argument (0:) as a floating-point number with 2 decimal digits (F2) and append % at the end."

     

    If you run tests on one locale but need to format text for another locale, you can specify the locale as a parameter:

    var number = 4;
    var culture = dotNET.System_Globalization.CultureInfo.zctor("de-de");
    var str = dotNET.System.String.Format_3(culture, "{0:F2}%", number).OleValue;