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 2 1054
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
first parse that string to int by using var int=parseInt(string); then
use math.round(int); thats it This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Edward King |
last post by:
Hi!
I am trying to achieve the following:
I have a number of help pages (in the format help_nn.php where nn=helpid).
I want to be able to open a particular help page by calling the function...
|
by: TrvlOrm |
last post by:
HI There,
I have been struggling with JavaScript code for days now, and this is
my last resort! Please help...
I am trying to create a JavaScript slide show with links for Next
Slide,...
|
by: mike |
last post by:
Hello,
I am kind of new to this javascript stuff and I am constantly having
problems trying to get my webpage validated. I have the following
<script>printdate();</script> and when I validate it...
|
by: YZK |
last post by:
Hello. I'm not a Web developer, just a user, and I think I may have
somehow messed myself up majorly. I'm not quite sure how. Right now,
javascript used by websites I go to either does not work at...
|
by: Craig Keightley |
last post by:
Please help, i have attached my page which worksin IE but i cannnot get the
drop down menu to fucntion in firefox. Any one have any ideas why?
Many Thanks
Craig
...
|
by: Erland |
last post by:
Hello All,
I am using AJAX library( AjaxEngine from
http://www.mathertel.de/AJAXEngine/) and having problems and hope
someone here can help me.
I have some piece of javascript code that I...
|
by: JumpingOffPlace |
last post by:
Hi,
I'm hoping that the wealth of knowledge here can stop me from spinning
my wheels on this syntax error for hours. :)
Below is the code, and the error I am recieving....
Code:
<!DOCTYPE...
|
by: aljamala |
last post by:
Hi,
I keep getting this warning on a page, but I do not know what the
problem is...does anyone have an idea about what could be wrong?
line 88 column 7 - Warning: missing </formbefore <td>
it...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: gubbachchi |
last post by:
Hi all,
In my application I need to display the data fetched from mysql database after the user selects date from javascript calender. I have written the code in which after the user selects the...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |