Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help with javascript

Reply
Thread Tools

Help with javascript

 
 
Morten Snedker
Guest
Posts: n/a
 
      12-01-2006
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
 
Reply With Quote
 
 
 
 
shekhargood
Guest
Posts: n/a
 
      12-01-2006
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 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


 
Reply With Quote
 
 
 
 
shekhargood
Guest
Posts: n/a
 
      12-01-2006
first parse that string to int by using var int=parseInt(string); then
use math.round(int); thats it

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
JavaScript or not JavaScript Mark Rae ASP .Net 36 09-09-2006 01:12 PM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
Javascript -> Applet: variable reset after method call from javascript?! mcdeveloper Java 1 06-13-2006 08:34 AM
Need your help, I am new with javascript, what do I wrong? javascript form validation suddenly doesn´t work francisco lopez Javascript 2 12-30-2004 12:18 PM



Advertisments