web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Convert a Currency type number to letters

(0) ShareShare
ReportReport
Posted on by 5
I am faced with the challenge of creating a report in Reporting Service on a sales contract.
In it I must automate the following:
1530 $ which is saved as the Estimated Income field in the Opportunity entity, I need to pass this to letters in another text type field Ex: One thousand five hundred and thirty US dollars with 00/100.
I have tried to do it with a Javascript code but it does not work for me.

Has anyone here managed to do this before?

I leave the code that I am trying to make work.
It does not give an error, but it does not return anything.
----------------------------------------------------------------------------------------------------------------------------
function letras() {
var num = Xrm.Page.getAttribute("estimatedvalue").getValue();

function Unidades(num){
switch(num)
{
case 1: return 'UN';
case 2: return 'DOS';
case 3: return 'TRES';
case 4: return 'CUATRO';
case 5: return 'CINCO';
case 6: return 'SEIS';
case 7: return 'SIETE';
case 8: return 'OCHO';
case 9: return 'NUEVE';
}
return ' ';
}//Unidades()
function Decenas(num){

var decena = Math.floor(num/10);
var unidad = num - (decena * 10);

switch(decena)
{
case 1:
switch(unidad)
{
case 0: return 'DIEZ';
case 1: return 'ONCE';
case 2: return 'DOCE';
case 3: return 'TRECE';
case 4: return 'CATORCE';
case 5: return 'QUINCE';
default: return 'DIECI' + Unidades(unidad);
}
case 2:
switch(unidad)
{
case 0: return 'VEINTE';
default: return 'VEINTI' + Unidades(unidad);
}
case 3: return DecenasY('TREINTA', unidad);
case 4: return DecenasY('CUARENTA', unidad);
case 5: return DecenasY('CINCUENTA', unidad);
case 6: return DecenasY('SESENTA', unidad);
case 7: return DecenasY('SETENTA', unidad);
case 8: return DecenasY('OCHENTA', unidad);
case 9: return DecenasY('NOVENTA', unidad);
case 0: return Unidades(unidad);
}
}//Unidades()

function DecenasY(strSin, numUnidades) {
if (numUnidades > 0)
return strSin + ' Y ' + Unidades(numUnidades)

return strSin;
}//DecenasY()

function Centenas(num) {
var centenas = Math.floor(num / 100);
var decenas = num - (centenas * 100);

switch(centenas)
{
case 1:
if (decenas > 0)
return 'CIENTO ' + Decenas(decenas);
return 'CIEN';
case 2: return 'DOSCIENTOS ' + Decenas(decenas);
case 3: return 'TRESCIENTOS ' + Decenas(decenas);
case 4: return 'CUATROCIENTOS ' + Decenas(decenas);
case 5: return 'QUINIENTOS ' + Decenas(decenas);
case 6: return 'SEISCIENTOS ' + Decenas(decenas);
case 7: return 'SETECIENTOS ' + Decenas(decenas);
case 8: return 'OCHOCIENTOS ' + Decenas(decenas);
case 9: return 'NOVECIENTOS ' + Decenas(decenas);
}

return Decenas(decenas);
}//Centenas()

function Seccion(num, divisor, strSingular, strPlural) {
var cientos = Math.floor(num / divisor)
var resto = num - (cientos * divisor)

var letras = '';

if (cientos > 0)
if (cientos > 1)
letras = Centenas(cientos) + ' ' + strPlural;
else
letras = strSingular;

if (resto > 0)
letras += '';

return letras;
}//Seccion()

function Miles(num) {
var divisor = 1000;
var cientos = Math.floor(num / divisor)
var resto = num - (cientos * divisor)

var strMiles = Seccion(num, divisor, 'UN MIL', 'MIL');
var strCentenas = Centenas(resto);

if(strMiles == '')
return strCentenas;

return strMiles + ' ' + strCentenas;
}//Miles()

function Millones(num) {
var divisor = 1000000;
var cientos = Math.floor(num / divisor)
var resto = num - (cientos * divisor)

var strMillones = Seccion(num, divisor, 'UN MILLON DE', 'MILLONES DE');
var strMiles = Miles(resto);

if(strMillones == '')
return strMiles;

return strMillones + ' ' + strMiles;
}//Millones()

return function NumeroALetras(num, currency) {
currency = currency || {};
var data = {
numero: num,
enteros: Math.floor(num),
centavos: (((Math.round(num * 100)) - (Math.floor(num) * 100))),
letrasCentavos: '',
letrasMonedaPlural: currency.plural ,
letrasMonedaSingular: currency.singular,
letrasMonedaCentavoPlural: currency.centPlural ,
letrasMonedaCentavoSingular: currency.centSingular
};

if (data.centavos > 0) {
data.letrasCentavos = 'CON ' + (function () {
if (data.centavos == 1)
return Millones(data.centavos) + ' ' + data.letrasMonedaCentavoSingular;
else
return Millones(data.centavos) + ' ' + data.letrasMonedaCentavoPlural;
})();
};

if(data.enteros == 0)
return 'CERO ' + data.letrasMonedaPlural + ' ' + data.letrasCentavos;
if (data.enteros == 1)
return Millones(data.enteros) + ' ' + data.letrasMonedaSingular + ' ' + data.letrasCentavos;
else
return Millones(data.enteros) + ' ' + data.letrasMonedaPlural + ' ' + data.letrasCentavos;
};
Xrm.Page.getAttribute("new_importeenletras").setValue((letras(num, {
plural: 'DÓLARES ESTADOUNIDENSES',
singular: 'DÓLAR ESTADOUNIDENSE',
centPlural: 'centavos',
centSingular: 'centavo'
})));
}

-------------------------------------------------------------------------------------------------------------------------
Thank you very much for the help.
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans