473,804 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS Sort Function

Hi there,

I have a JS/ASP application that sorts a SQL populated table.
This works great, and sorts the data fine, apart from my currency columns.
It wants to read the data as text as far as i can gather. Ths data in ASP
looks like this -
<% =formatcurrency (RS("income"),2 )%>

I have tried changing this to a number (formatnumber) and hard coding a £
sign, yet it still wants to read the data as text, rather than numerical?
How can i get my JS function to read currency or if not, eliminate the
forehand figures. I need the data to appear as a currency, yet be sorted as
a number (rather than taking the 2st digit)

If it would help i can post my JS script, but i was wondering if this is a
common problem (sorting currency) and there was a universal solution around
this.

Thanks

--
Thanks in advance

Fawke

Please remove ANTI and SPAM
from my email address before emailing me.

www.bradflack.com
Jul 19 '05 #1
2 1499
It all depends where you're doing the sort. I think the JS function would
be useful.
"Fawke101" <gu*@ANTIbradfl ack.SPAMcom> wrote in message
news:uS******** ******@TK2MSFTN GP11.phx.gbl...
Hi there,

I have a JS/ASP application that sorts a SQL populated table.
This works great, and sorts the data fine, apart from my currency columns.
It wants to read the data as text as far as i can gather. Ths data in ASP
looks like this -
<% =formatcurrency (RS("income"),2 )%>

I have tried changing this to a number (formatnumber) and hard coding a £
sign, yet it still wants to read the data as text, rather than numerical?
How can i get my JS function to read currency or if not, eliminate the
forehand figures. I need the data to appear as a currency, yet be sorted as a number (rather than taking the 2st digit)

If it would help i can post my JS script, but i was wondering if this is a
common problem (sorting currency) and there was a universal solution around this.

Thanks

--
Thanks in advance

Fawke

Please remove ANTI and SPAM
from my email address before emailing me.

www.bradflack.com

Jul 19 '05 #2
"Fawke101" <gu*@ANTIbradfl ack.SPAMcom> writes:
I have a JS/ASP application that sorts a SQL populated table.
This works great, and sorts the data fine, apart from my currency columns.
It wants to read the data as text as far as i can gather. Ths data in ASP
looks like this -
<% =formatcurrency (RS("income"),2 )%>

I have tried changing this to a number (formatnumber) and hard coding a £
sign, yet it still wants to read the data as text, rather than numerical?


The sort function can sort anything, provided the appropriate
comparison function. However, the default comparison function converts
its arguments to strings and does lexical comparison. So, you must supply
the comparison function for your numbers.
E.g.:

// convert currency string to number (ignores prefixed £ and $, but
// can be extended)
function valueOfCurrency (string) { // zero or two decimals
if (match = /^[$£](\d+)(\.(\d\d)) ?$/.exec(string)) {
return Number(match[1])*100 + Number(match[3]); // pence or cent
}
return -1;
}

function compareCurrency (a,b) {
return valueOfCurrency (a)-valueOfCurrency (b);
}

var money = ["$24.20","$1000 000","$125.95", "$1.25"];
alert(money.sor t(compareCurren cy));
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
6213
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn, date and several other bits of info too. I can do a simple sort over the first field (title as it turns out), and that is fine as far as it gets:
4
3770
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
4
3284
by: Seeker | last post by:
Hi, I have an array of objects. My object definition is given below: function tempArray(code,height,weight) { this.code = code; this.height = height; this.weight = weight; }
7
4020
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I do a database query and what I wind up with is a structure Q of arrays: Q.f1 is field f1 in row n, Q.f1.length == Q.f2.length == Q.f3.length is the record count of the query. (This representation is of course backwards, but that's what...
7
3550
by: Ireneusz SZCZESNIAK | last post by:
I want to sort a vector with the std::sort function. There are two functions: one with two arguments, the other with three arguments. I am using the one with three arguments. I noticed that there is a huge overhead of using this function, which comes from copying the function object, i.e., the object that compares the elements of the vector, which is passed to the function not by reference but by value. Now, at the end of this mail...
5
8989
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need something more sophistictated like a vector of row objects. The data is of this format (same number of columns for each row): A, x, y, z, ...
7
2456
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my sort()". I'd heard you can do this within a namespace: namespace Fixed { using namespace std;
20
4087
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort†method. For example: li=;
21
3228
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
18
2348
by: xahlee | last post by:
Last year, i've posted a tutorial and commentary about Python and Perl's sort function. (http://xahlee.org/perl-python/sort_list.html) In that article, i discussed a technique known among juvenile Perlers as the Schwartzian Transform, which also manifests in Python as its “key†optional parameter. Here, i give a more detailed account on why and how of this construct. ----
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.