Monetary unit with JSON

2

I'm getting a JSON currency format as follows

"Preco" : "2299.0000"

Appearing on my form (ASP Classic / HTML):

  

$ 22,990,000.00

How to do this treatment? Do you have to use JS?

The correct value that should appear is: $ 2299.00 .

    
asked by anonymous 22.12.2014 / 11:51

3 answers

2

Hello,

You can try to format the number like this:

FormatNumber(12345.67899)

The output will be:

12,345.68

More information here .

    
22.12.2014 / 15:41
1

Hello now I usually use the two functions below in JavaScript and work perfectly, I will post below and after I will leave some examples ok.

In JavaScript:

function moedaParaNumero(valor) {
    return isNaN(valor) == false ? parseFloat(valor) : parseFloat(valor.replace("R$", "").replace(".", "").replace(",", "."));

/* Exemplos:
* var a = moedaParaNumero("R$ 10,00"); 
* var b = moedaParaNumero("R$ 100"); 
* var c = moedaParaNumero("0,50"); 
* var d = moedaParaNumero("1.500,00"); 
* var e = moedaParaNumero("89");
* Resultado 10 - 100 - 0.5 - 1500 - 89    
*/
}

function numeroParaMoeda(n, c, d, t) {
    c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");

/* Exemplos:
* var a = numeroParaMoeda(10);
* var b = numeroParaMoeda(100);
* var c = numeroParaMoeda(0.5);
* var d = numeroParaMoeda(1500);
* var e = numeroParaMoeda(89);
* Resultado "10,00" - "100,00" - "0,50" - "1.500,00" - "89,00"
*/
}

In ASP Classic

<%
'Exemplo 01: FormatCurrency
response.write(FormatCurrency(20000))
'Resposta $20,000.00
'Referência http://www.w3schools.com/asp/func_formatcurrency.asp

'Exemplo 02: FormatNumber
response.write(FormatNumber(20000))
'Resposta 20,000.00
'Referência http://www.w3schools.com/asp/func_formatnumber.asp
%>
    
20.02.2016 / 15:12
0

If it continues to be wrong using FormatNumber it is because you may need to replace the semicolon before. Depending on the configuration of IIS it considers the national standard for decimal separation.

resultado = replace(rsGrid("preco"),".",",")
    
22.08.2016 / 21:10