Manage Learn to apply best practices and optimize your operations.

# Code To Convert A Number Value To A Text String. Useful In Check Printing Or Report Writing Apps.

I don't know how the formula will look on the web page, since there is a lot
there :) But it should come out correctly when you cut and paste it!

PURPOSE: This code will convert a number value to a text string. The current
limitation is that the number can be no longer than five digits, and only whole
numbers are accounted for.

TO USE: Paste this code in a "Computed" field and replace "Amount" (in the
first line) to the value you want to convert it will take the number and make
it into a string.

APPLICATION: I used this in an application where I integrated IntelliPrint,
and I needed to print checks with the wording spelled out. (ex. \$1230.00 would
be ONE THOUSAND TWO HUNDRED THIRTY DOLLARS)
txtAmount := @Text( @Integer(Amount) );
length := @Length( txtAmount );

fromSingle := "0" : "1" : "2" : "3" : "4" : "5" : "6" : "7" : "8" : "9";
toSingle := " " : " ONE" : " TWO" : " THREE" : " FOUR" : " FIVE" : " SIX" : "
SEVEN" : " EIGHT" : " NINE";

fromTens := "0" : "1" : "2" : "3" : "4" : "5" : "6" : "7" : "8" : "9";
toTens := " " : " TEN" : " TWENTY" : " THIRTY" : " FOURTY" : " FIFTY" : "
SIXTY" : " SEVENTY" : " EIGHTY" : " NINETY";

fromDouble := "11" : "12" : "13" : "14" : "15" : "16" : "17" : "18" : "19";
toDouble := " ELEVEN" : " TWELVE" : " THIRTEEN" : " FOURTEEN" : " FIFTEEN" : "
SIXTEEN" : " SEVENTEEN" : " EIGHTEEN" : " NINETEEN";

value :=
@If( length=5;
@Do( @If( @Length( @ReplaceSubstring( @Left( txtAmount; 2 ); fromDouble;
toDouble ) ) > 2;
@ReplaceSubstring( @Left( txtAmount; 2 ); fromDouble;
toDouble ) + " THOUSAND ";
@ReplaceSubstring( @Left( txtAmount; 1 ); fromTens; toTens )
+ @ReplaceSubstring( @Right( @Left( txtAmount; 2 ); 1); fromSingle; toSingle )
+ " THOUSAND " ) ) +
@ReplaceSubstring( @Right( @Left( txtAmount; 3 ); 1);
fromSingle; toSingle ) + @Do( @If( @Right( @Left( txtAmount; 3 ); 1) = "0"; "";
" HUNDRED ") ) +
@Do( @If( @Length( @ReplaceSubstring( @Right(
txtAmount; 2 ); fromDouble; toDouble ) ) > 2;
@ReplaceSubstring( @Right(
txtAmount; 2 ); fromDouble; toDouble );
@ReplaceSubstring( @Left( @Right(
txtAmount; 2 ); 1 ); fromTens; toTens ) + @ReplaceSubstring( @Right( txtAmount;
1); fromSingle; toSingle ) ) );
length=4;
@ReplaceSubstring( @Left( txtAmount; 1 ); fromSingle; toSingle ) + " THOUSAND "
+
@ReplaceSubstring( @Right( @Left( txtAmount; 2 ); 1); fromSingle; toSingle ) +
@Do( @If( @Right( @Left( txtAmount; 2 ); 1) = "0"; ""; " HUNDRED ") ) +
@Do( @If( @Length( @ReplaceSubstring( @Right( txtAmount; 2 );
fromDouble; toDouble ) ) > 2;
@ReplaceSubstring( @Right( txtAmount; 2 );
fromDouble; toDouble );
@ReplaceSubstring( @Left( @Right(
txtAmount; 2 ); 1 ); fromTens; toTens ) + @ReplaceSubstring( @Right( txtAmount;
1); fromSingle; toSingle ) ) );
length=3;
@ReplaceSubstring( @Left( txtAmount; 1 ); fromSingle; toSingle ) + " HUNDRED " +
@Do( @If( @Length( @ReplaceSubstring( @Right( txtAmount; 2 );
fromDouble; toDouble ) ) > 2;
@ReplaceSubstring( @Right( txtAmount; 2 );
fromDouble; toDouble );
@ReplaceSubstring( @Left( @Right(
txtAmount; 2 ); 1 ); fromTens; toTens ) + @ReplaceSubstring( @Right( txtAmount;
1); fromSingle; toSingle ) ) );
length=2;
@Do( @If( @Length( @ReplaceSubstring( @Left( txtAmount; 2 ); fromDouble;
toDouble ) ) > 2;
@ReplaceSubstring( @Left( txtAmount; 2 ); fromDouble;
toDouble );
@ReplaceSubstring( @Left( txtAmount; 1 ); fromTens; toTens )
+ @ReplaceSubstring( @Right( @Left( txtAmount; 2 ); 1); fromSingle; toSingle )
) );
length=1;
@ReplaceSubstring( @Left( txtAmount; 1 ); fromSingle; toSingle );
"");

@Trim(value) + " DOLLARS"

#### Start the conversation

Send me notifications when other members comment.

## SearchWindowsServer

• ### February Patch Tuesday resolves IE zero-day

Microsoft released security updates for 99 unique vulnerabilities, including an Internet Explorer flaw the company had notified ...

• ### What's new with PowerShell error handling?

PowerShell 7 introduces a new cmdlet to assist administrators who wanted a better way to find out what broke in the scripts they ...

• ### Why move to PowerShell 7 from Windows PowerShell?

The next major release of this venerable automation tool features performance improvements and a bevy of new features that could ...

## Search400

• ### iSeries tutorials

Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

• ### V6R1 upgrade planning checklist

When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

• ### Connecting multiple iSeries systems through DDM

Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

## SearchDataCenter

• ### Initiative aims to improve data center incident reporting

The Data Center Incident Reporting Network hopes to pull back the smoke screen on software and hardware issues to improve ...

• ### A guide to GPU implementation and activation

Data center GPU usage goes beyond hardware. Admins must work with vendors and developers to have the right software architecture ...

• ### Key components for negotiating an HPC colocation contract

When it comes to HPC colocation, there are specialized areas to cover in a service-level agreement. Review provider protocols for...

## SearchContentManagement

• ### Test yourself on the differences between SharePoint and OneDrive

Businesses use Microsoft SharePoint and OneDrive capabilities for a number of reasons. Test your knowledge on the differences ...

• ### Akeneo rolls out newest version of PIM software

Akeneo PIM version 4.0 features digital asset manager, API-integrated connection modules and AI attribute mapping to better ...

• ### Get to know 4 workflow automation tools

Workflow automation can benefit businesses by making manual processes digital, giving employees more time to work on other tasks....

Close