Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting javascript to java

vshanDec 29 2008 — edited Dec 29 2008
I created this code but now requirement is that i got to do this in java, how can i convert this

function makeArray0() {
for (i = 0; i<makeArray0.arguments.length; i++)
this[i] = makeArray0.arguments;
}

var numbers = new makeArray0('','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Eleven','Twelve','Thirteen','Fourteen','Fifthteen','Sixteen','Seventeen','Eighteen','Nineteen');

var numbers10 = new makeArray0('','Ten','Twenty','Thirty','Fourty','Fifty','Sixty','Seventy','Eighty','Ninety');

function chequeAmount(input) {
var rupees = Math.floor(input);
var paise = Math.round((input*100 - rupees*100));
var thousands = (rupees - rupees % 1000) / 1000;

var lakhs = 0;
var crores = 0;
rupees -= thousands * 1000;
if(thousands > 99) {
lakhs = Math.floor(thousands / 100) ;
thousands = thousands - lakhs*100;
}
if(lakhs > 99) {
crores = Math.floor(lakhs / 100) ;
lakhs = lakhs - crores*100;
}
if(crores > 99) {
alert ("Invalid amount");
return '';
}

var hundreds = (rupees - rupees % 100) / 100;
rupees -= hundreds * 100;

var output = '';

/* if (cores > 0) {
(crores > 0 ? digiCombine(crores) + ' Crores ' : '')
alert(WHOOOii);
}
else {
(crores > 0 ? digiCombine(crores) + ' Crores ' : '') }
alert(HIII); */

var filterCrore=digiCombine(crores);
//alert(filterCrore);
if (filterCrore == 'One'){
//alert('Im home with ONE');
var CroresDisplay= ' Crore ';
}else {
//alert('Im home with SOMETHING ELSE');
var CroresDisplay= ' Crores ';
}
// customise Lakh disply
var filterLakh=digiCombine(lakhs);
//alert(filterLakh);
if (filterLakh == 'One'){
// alert('Im home with ONE');
var LakhsDisplay= ' Lakh ';
}else{
//alert('Im home with SOMETHING ELSE');
var LakhsDisplay= ' Lakhs ';
}

output += (crores > 0 ? filterCrore + CroresDisplay : '') +

((( lakhs >0 || thousands > 0 || hundreds > 0 || rupees > 0 || paise > 0 ) && crores > 0) ? 'and ' : '') +

(lakhs > 0 ? digiCombine(lakhs) + LakhsDisplay : '') +

(thousands > 0 ? digiCombine(thousands) + ' Thousand ' : '') +

(hundreds > 0 ? digiCombine(hundreds) + ' Hundred ' : '') +
(rupees > 0 ? digiCombine(rupees) + ' ' : '') +

((lakhs >0 || thousands > 0 || hundreds > 0 || rupees > 0) ? 'Rupees ' : '') +
((Math.floor(input) > 0 && paise > 0) ? 'and ' : '') +
(paise > 0 ? digiCombine(paise) + ' Paise' : '');

//var ping = output.substring(0,1).toUpperCase() + output.substring(1);

//alert(ping);
return output.substring(0,1).toUpperCase() + output.substring(1);
}

function digiCombine(i) {

if (i<20) return numbers[i];
//alert(i);
var tens = (i - i % 10) / 10, units = i - (i - i % 10);
//alert(tens);
return numbers10[tens] + ((tens > 0 && units > 0) ? '-' : '') + numbers[units];
alert(numbers[units]);
}

-vidu

Edited by: vidushan on Dec 29, 2008 12:04 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 26 2009
Added on Dec 29 2008
3 comments
674 views