Help with javascript

M

Morten Snedker

I'm fairly new to aspnet, actually I'm on my very first project. I've
worked with vb.net, vb and vba through some years, but with aspnet
I've been forced into something new: javascript.

I'm all new to javascript and need some help with the script below. It
is supposed to return a number in Danish format, which would be
something like
10.500,00
that is . as 1000-separator and , before the two decimals.

However, if I enter 1000,50 it returns
100.050,00

I can't figure out where the fault is. Can someone help me?


num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + ',' + cents);


Regards /Snedker
 
S

shekhargood

first u must parse that string to int with var
roundedValue=parseInt(stringname);then use math.round(roundedValue);
thats it
 
S

shekhargood

first parse that string to int by using var int=parseInt(string); then
use math.round(int); thats it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top