Coldfusion converts a number to text

I have a coldfusion application in which I calculate the number remaining from a specific object.

So I have an integer ... for example 9.

But I need to print it on the screen in text form .... like nine.

Is there a built-in function for this? I googled and could not find it.

+4
source share
3 answers

Stephen is right, the direct answer is that there is no built-in function for this, but there is UDF here that you can play with with NumberAsString

+8
source

Not. I'm afraid there is no built-in function for this.

You will need to write a user-defined function or method in cfc to do this for you.

+1
source

This is how I did it, after much effort, I could add. I wrote this under ColdFusion 4.5, so your mileage may vary.

The key breaks the numbers into 3-row fragments, then displays each piece with the corresponding addenum (million, thousands, etc.) and, of course, deals with random zeros and numbers in adolescence. The first lists can be used to change languages, but require that the order is correct (i.e., first record = 1). This was for verification, where the figure was to be written out in English, so the set of variables is “verification”. The variable you are converting is a digit named "check_amount".

I apologize for the lousy code - I'm a designer, not a programmer. There are so many recurring sections that need to be reorganized, but they are designed to work with leading zeros and teens, mostly.

Third editing is lovely, I suppose. This final (working) version now correctly processes zero dollars.

<cfoutput><cfif IsNumeric(check_amount)> <!--- is it a number? ---> <cfparam name="write_single" default="one,two,three,four,five,six,seven,eight,nine, "> <cfparam name="write_double" default=" ,twenty,thirty,fourty,fifty,sixty,seventy,eighty,ninety"> <cfparam name="teens" default="11,12,13,14,15,16,17,18,19"> <cfparam name="teens_written" default="eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen"> <cfparam name="triplet_after" default="hundred, thousand, million, billion, trillion, quadrillion, quintillion, hexillion, heptillion, octillion, nonillion, decillion, unodecillion, duodecillion"> <cfset x=#ListLen(DecimalFormat(check_amount))#> <!--- seperate the number into sections, using the built-in Decimal Format to make it into a list of 3-digit numbers ---> <cfloop list="#DecimalFormat(check_amount)#" index="trips" delimiters=","> <!--- seperate the number into hundreds tens and singles, making the teens exception ---> <cfif #Evaluate(Int(trips))# NEQ "0"> <cfif Len(Int(trips)) EQ "3"> <cfif mid(Int(trips), 1, 1) EQ "0"> <cfif #ListFind(teens, right(Int(trips), 2), ',')# NEQ "0"> #listGetAt(teens_written, ListFind(teens, right(int(trips), 2), ','), ',')# <cfelse> #listGetAt(write_double, mid(Int(trips), 2, 1), ',')# <cfif mid(Int(trips), 3, 1) NEQ "0"> #listGetAt(write_single, mid(Int(trips), 3, 1), ',')# </cfif> </cfif> <cfelse> #listGetAt(write_single, mid(Int(trips), 1, 1), ',')# #listGetAt(triplet_after, 1, ',')# </cfif> <cfif mid(trips, 2, 1) NEQ "0"> <cfif #ListFind(teens, right(Int(trips), 2), ',')# NEQ "0"> #listGetAt(teens_written, ListFind(teens, right(int(trips), 2), ','), ',')# <cfelse> #listGetAt(write_double, mid(Int(trips), 2, 1), ',')# <cfif mid(trips, 3, 1) NEQ "0"> #listGetAt(write_single, mid(Int(trips), 3, 1), ',')# </cfif> </cfif> <cfelse> <cfif mid(trips, 3, 1) NEQ "0"> #listGetAt(write_single, mid(Int(trips), 3, 1), ',')# </cfif> </cfif> <cfelseif Len(Int(trips)) EQ "2" AND mid(Int(trips), 1, 1) NEQ "0"> <cfif #ListFind(teens, right(Int(trips), 2), ',')# NEQ "0"> #listGetAt(teens_written, ListFind(teens, right(int(trips), 2), ','), ',')# <cfelse> #listGetAt(write_double, mid(Int(trips), 1, 1), ',')# <cfif mid(trips, 2, 1) NEQ "0"> #listGetAt(write_single, mid(Int(trips), 2, 1), ',')# </cfif> </cfif> <cfelseif Len(Int(trips)) EQ 1 AND mid(int(trips), 1, 1) NEQ "0"> #listGetAt(write_single, mid(Int(trips), 1, 1), ',')# </cfif> <!--- deal with the thousands and millions seperators, doesn't include hundreds on last loop ---> <cfif x NEQ "1">#listGetAt(triplet_after, x, ',')#</cfif> <cfelse> <!--- Zero Dollars? How about... ---><cfif x EQ #ListLen(DecimalFormat(check_amount))#> No </cfif> </cfif> <cfset x=x-1><!--- next loop, next valuations ---> </cfloop> <!--- output tailing text and cents in check format ---> Dollars and <sup>#right(DecimalFormat(check_amount), 2)#</sup>/<sub>100</sub> cents</p> </cfif></cfoutput> 
+1
source

Source: https://habr.com/ru/post/1300931/


All Articles