Question

In: Computer Science

i need code in javascript or htmlt convert 0 to 999 numbers into word

i need code in javascript or htmlt convert 0 to 999 numbers into word

Solutions

Expert Solution

Java Script code to convert numbers into word

----------------------------------------------------------------------------------------------------------------------------

<script language="javascript">


function numToString(x)
{
var r=0;
var txter=x;
var sizer=txter.length;
var numStr="";
if(isNaN(txter))
{
alert(" Invalid number");
exit();
}
var n=parseInt(x);
var places=0;
var str="";
var entry=0;
while(n>=1)
{
r=parseInt(n%10);

if(places<3 && entry==0)
{
numStr=txter.substring(txter.length-0,txter.length-3) // Checks for 1 to 999.
str=onlyDigit(numStr); //Calls function for last 3 digits of the value.
entry=1;
}

if(places==3)
{
numStr=txter.substring(txter.length-5,txter.length-3)
if(numStr!="")
{
str=onlyDigit(numStr)+ " Thousand "+str;
}
}

if(places==5)
{
numStr=txter.substring(txter.length-7,txter.length-5) //Substring for 5 place to 7 place of the string
if(numStr!="")
{
str=onlyDigit(numStr)+ " Lakhs "+str; //Appends the word lakhs to it
}
}

if(places==6)
{
numStr=txter.substring(txter.length-9,txter.length-7) //Substring for 7 place to 8 place of the string
if(numStr!="")
{
str=onlyDigit(numStr)+ " Crores "+str;        //Appends the word Crores
}
}

n=parseInt(n/10);
places++;
}
alert(str);
}


function onlyDigit(n)
{
//Arrays to store the string equivalent of the number to convert in words
var units=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'];
var randomer=['','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'];
var tens=['','Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'];
var r=0;
var num=parseInt(n);
var str="";
var pl="";
var tenser="";
while(num>=1)
{
r=parseInt(num%10);
tenser=r+tenser;
if(tenser<=19 && tenser>10) //Logic for 10 to 19 numbers
{
str=randomer[tenser-10];
}
else
{
if(pl==0)        //If units place then call units array.
{
str=units[r];
}
else if(pl==1)    //If tens place then call tens array.
{
str=tens[r]+" "+str;
}
}
if(pl==2)        //If hundreds place then call units array.
{
str=units[r]+" Hundred "+str;
}

num=parseInt(num/10);
pl++;
}
return str;
}

</script>


<form name="fm" id="fm">

<input type="text" name="txtinput" id="txtinput" maxlength="9" />
<input type="button" onclick="numToString(txtinput.value)" id="show" />

</form>

---------------------------------------------------------------------------------------------------------------------------------


Related Solutions

Write a java code to find the following. For numbers 501 to 999, how many numbers...
Write a java code to find the following. For numbers 501 to 999, how many numbers will have the sum of the digits equal to 10. 501, sum of digits=6 502, sum of digits=7 503, sum of digits=8 504, sum of digits=9 505, sum of digits=10 506, sum of digits=11
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
I need an idea of Java code that will convert an integer (1 to 3,999) into...
I need an idea of Java code that will convert an integer (1 to 3,999) into roman numerals using if statements; arrays and loops sadly aren't allowed and that's all I can come up with.
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., 12321 This is the code i have, but it doesnt work. PLEASE MAKE SURE IT WORK BEFORE POST ANSWER, I GOT @ CODE THAT DID WORK BEFORE HTML JavaScript Palindrome Exercise rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" /> Palindrome Enter a positive number: Is this a palindrome? No...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome or no.
Hi i need a c++ program that can convert charactor into numbers pseodocode user input their...
Hi i need a c++ program that can convert charactor into numbers pseodocode user input their name for example john every single charactor should have a value so it return correct result eg: j=2, o=1, h=7,n=2 and display these numbers if you may need any question to ask me, i will be very happy to answer them. Thanks! example project close but not accurate #include #include #include #include #include #include #include #include #define INPUT_SIZE 8 using namespace std; // Function...
Convert the following values into binary numbers for each word and place the binary values in...
Convert the following values into binary numbers for each word and place the binary values in the two-dimensional array in their proper order of words. Value Binary Number Equivalent Word 0 462,91210 Word 1 1142008 Word 2 5420h Word 3 20,992d Word 4 1104208 Word 5 6102008 Word 6 9F88h Word 7 20,49610 Word 8 502416 Word 9 1101018 Word 10 71082h
JavaScript Write out a function that takes in array of numbers. You do not need to...
JavaScript Write out a function that takes in array of numbers. You do not need to check if each item of the array is a number, assume this has already been done. Create a new array using the map function that that the original item and adds 4 to it. Then iterate through the new array and log each item to the console. If you do not use map it will be counted wrong. Call your function with the following...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT