cancel
Showing results for 
Search instead for 
Did you mean: 

Use aqString.format to generate a number with the thousands separator

SOLVED
Contributor

Use aqString.format to generate a number with the thousands separator

It can't possibly be this hard, but I can't for the life of me figure out how to do it!



What I want:



aqString.Format("???", 1) = 1

aqString.Format("???", 100) = 100

aqString.Format("???", 100000) = 100,000

aqString.Format("???", 10000000) = 10,000,000



What does "???" need to be?



No examples in Smartbear documentation for creating this format.



David Peterson Senior QA Analyst Fulcrum Consulting
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Manager

RE: Use aqString.format to generate a number with the thousands separator

Hi David,

 

As far as I know, aqString.Format cannot do this, but you can use the .NET System.Format method instead:
// JScript
dotNET.System.String.Format("{0:n0}", 1000).OleValue

It uses the current locale's thousands separator - comma/space/period etc.

 

If you run tests on different locales and want to always format with a comma, you can use something like this:
// JScript
function ToString(number)
{
var culture = dotNET.System_Globalization.CultureInfo.zctor("en-US");
var args = dotNET.System_Collections.ArrayList.zctor();
args.Add(number);
var str = dotNET.System.String.Format_3(culture, "{0:n0}", args.ToArray()).OleValue;
return str;
}
---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

2 REPLIES 2
Highlighted
Regular Contributor

RE: Use aqString.format to generate a number with the thousands separator

Hi David,



Format Specifiers should help.



In your code it should be "%i".



Sincerely
Simon Glet
Highlighted
Community Manager

RE: Use aqString.format to generate a number with the thousands separator

Hi David,

 

As far as I know, aqString.Format cannot do this, but you can use the .NET System.Format method instead:
// JScript
dotNET.System.String.Format("{0:n0}", 1000).OleValue

It uses the current locale's thousands separator - comma/space/period etc.

 

If you run tests on different locales and want to always format with a comma, you can use something like this:
// JScript
function ToString(number)
{
var culture = dotNET.System_Globalization.CultureInfo.zctor("en-US");
var args = dotNET.System_Collections.ArrayList.zctor();
args.Add(number);
var str = dotNET.System.String.Format_3(culture, "{0:n0}", args.ToArray()).OleValue;
return str;
}
---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors