first u must parse that string to int with var
roundedValue=parseInt(stringname);then use math.round(roundedValue);
thats it
On Dec 1, 1:03 pm, Morten Snedker <morten_spammenot_ATdbconsult.dk>
wrote:
> 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 1000separator 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
