Convert numbers to text

I saw that there is a way to convert numbers to text in Numbers, and I’d like to find out how to do it. Can be used for printing a check from a check register.

Windows, Windows 6

Posted on Mar 3, 2024 8:46 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 4, 2024 5:52 AM

Turns out AppleScript is not that easy to do either, though it's easy to use once it's done.


  1. Copy-paste script below to Script Editor (in Applications > Utilities).
  2. Select a number or numbers in a Numbers table.
  3. Click the triangle run button in Script Editor.
  4. Paste the converted "numbers" into a column wherever you like (I clicked B2 once and pasted).


Test results (after converting to Capitalized at Format > Font > Capitalization):




If the script doesn't "do anything" you may need to check System Settings > Privacy & Security > Accessibility to enable Script Editor.


SG



The script:


use framework "Foundation"
use scripting additions
tell front document of application "Numbers"
	tell active sheet
		tell (first table whose selection range's class is range)
			set outStr to ""
			repeat with aCell in cells in (get its selection range)
				set theNumber to value of aCell
				set theInteger to theNumber div 1
				set theWords to my convertNumberToWords(theInteger)
				set theFraction to my convertDecimalToFraction(theNumber)
				set outStr to outStr & theWords & " and " & theFraction & return
			end repeat
		end tell
	end tell
end tell

set the clipboard to outStr

on convertNumberToWords(aNumber)
	tell current application's NSNumberFormatter to ¬
		set resultingText to localizedStringFromNumber_numberStyle_(aNumber, current application's NSNumberFormatterSpellOutStyle)
	return (resultingText as string)
end convertNumberToWords

on convertDecimalToFraction(aNumber)
	set integerPart to (aNumber div 1)
	set fractionPart to (aNumber - integerPart) * 100
	if fractionPart is 0 then
		return "00/100"
	else if fractionPart mod 10 is 0 then
		set fractionPart to fractionPart div 10
		return fractionPart & "/10"
	else
		return fractionPart div 1 & "/100" as text
	end if
end convertDecimalToFraction

2 replies
Question marked as Top-ranking reply

Mar 4, 2024 5:52 AM in response to Jacksbd

Turns out AppleScript is not that easy to do either, though it's easy to use once it's done.


  1. Copy-paste script below to Script Editor (in Applications > Utilities).
  2. Select a number or numbers in a Numbers table.
  3. Click the triangle run button in Script Editor.
  4. Paste the converted "numbers" into a column wherever you like (I clicked B2 once and pasted).


Test results (after converting to Capitalized at Format > Font > Capitalization):




If the script doesn't "do anything" you may need to check System Settings > Privacy & Security > Accessibility to enable Script Editor.


SG



The script:


use framework "Foundation"
use scripting additions
tell front document of application "Numbers"
	tell active sheet
		tell (first table whose selection range's class is range)
			set outStr to ""
			repeat with aCell in cells in (get its selection range)
				set theNumber to value of aCell
				set theInteger to theNumber div 1
				set theWords to my convertNumberToWords(theInteger)
				set theFraction to my convertDecimalToFraction(theNumber)
				set outStr to outStr & theWords & " and " & theFraction & return
			end repeat
		end tell
	end tell
end tell

set the clipboard to outStr

on convertNumberToWords(aNumber)
	tell current application's NSNumberFormatter to ¬
		set resultingText to localizedStringFromNumber_numberStyle_(aNumber, current application's NSNumberFormatterSpellOutStyle)
	return (resultingText as string)
end convertNumberToWords

on convertDecimalToFraction(aNumber)
	set integerPart to (aNumber div 1)
	set fractionPart to (aNumber - integerPart) * 100
	if fractionPart is 0 then
		return "00/100"
	else if fractionPart mod 10 is 0 then
		set fractionPart to fractionPart div 10
		return fractionPart & "/10"
	else
		return fractionPart div 1 & "/100" as text
	end if
end convertDecimalToFraction

Mar 3, 2024 12:01 PM in response to Jacksbd

There may be an AppleScript way to do it. I don't recall, though. The formulaic way gets pretty complicated but here goes...


Below is a spreadsheet from 2 years ago that does it in one cell with the help of an auxiliary table. It will do numbers up to 999,999,999.99 (positive and negative, but ignores zero).



Formula in B2 is really simple 🙂. I put it in a code block so it would not get truncated.

TRIM(IF(A<0,"Minus ","")&INDEX(Table 2::$A,TRUNC(ABS(A),−6)×10^−6+1)&" "&INDEX(Table 2::$B,TRUNC(ABS(A),−6)×10^−6+1)&" "&""&INDEX(Table 2::$A,MOD(TRUNC(ABS(A),−3),10^6)×10^−3+1)&" "&INDEX(Table 2::$C,MOD(TRUNC(ABS(A),−3),10^6)×10^−3+1)&" "&" "&INDEX(Table 2::$A,MOD(TRUNC(ABS(A),0),10^3)+1)&""&" "&IF(ABS(A)≥1," and ","")&IF(ABS(A)≠0,RIGHT("00"&MOD(ROUND(ABS(A),2),1)×10^+2,2)&"/100",""))


Copy paste it from this post to cell B2.


Column A of the auxiliary table is every number from one to Nine Hundred Ninety Nine. Columns B and C are as you see them, all the way to the end of the table. I'm trying to recall how I made column A. I didn't type it all by hand, that's for sure. I may have used a different number-to-text method to create the table. Assuming that's what I did, below is the other method. It is only good to 999.99 unless it is expanded further.



Formulas in the upper table are:

C2 =TRUNC(B2,−2)

D2 =TRUNC(B2,0)−C2

E2 =TRUNC(D2,−1)

F2 =D2−E2

G2 =ROUND((B2−C2−D2)×100,0)

H2 =

IF(C2>0,LOOKUP(C2,Table 2::A,Table 2::B)&" ","")&IF(E2>19,LOOKUP(E2,Table 2::A,Table 2::B)&" "&LOOKUP(F2,Table 2::A,Table 2::B),LOOKUP(D2,Table 2::A,Table 2::B))&IF(SUM(C2,D2,F2)>0," and ","")&G2&"/100"


To create text without the "and..." at the end, use this formula for H2 instead of the one above

IF(C2>0,LOOKUP(C2,Table 2::A,Table 2::B)&" ","")&IF(E2>19,LOOKUP(E2,Table 2::A,Table 2::B)&" "&LOOKUP(F2,Table 2::A,Table 2::B),LOOKUP(D2,Table 2::A,Table 2::B))


Do all numbers from 1 to 999 (don't go further) to turn them into text,Select them all, Copy, then Paste Formula Results into column A of the other method.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Convert numbers to text

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.