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"

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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

SearchContentManagement

Close