cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors