School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,475 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,758 people online right now. Registration is fast and FREE... Join Now!




XML add a comma into a number

 

XML add a comma into a number, Hi My feed comes in without a comma, I'd like to add one

bmcc81

26 May, 2009 - 09:26 AM
Post #1

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Hi,

I want to add a comma into my outputted data.

This is what the xml looks like:
CODE
<jackpots generated="2009-05-26T12:09:28-05:00">
<jackpot name="Bad Beat Jackpot">662890.32</jackpot>
<jackpot name="Caribbean Stud ($1)">25920.50</jackpot>
<jackpot name="Caribbean Stud ($5)">54258.86</jackpot>
</jackpots>


The Bad Beat Jackpot I want to have it fixed to that it reads out 662,890.32 notice the ,

How would I added that to the string?

Thanks,
bmcc81

User is offlineProfile CardPM
+Quote Post


bmcc81

RE: XML Add A Comma Into A Number

26 May, 2009 - 12:19 PM
Post #2

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
SO...

This is what I got so far, but doesn't seem to work.

CODE
var newsXML:XML = new XML();
newsXML.ignoreWhite = true;

var output:String = "";

newsXML.onLoad = function(success) {
    if (success) {

        var news:Array = newsXML.firstChild.childNodes;
        output = news[0].childNodes[0].nodeValue;
        trace(output);
        badText.text = output;



        for (var i:Number = output.length-1; i>=0; i--) {

            count++;
            badText += output.charAt(i);
            if ((count%3 == 0) && (i-1>=0)) {

                badText += ",";

            }
        }
    } else {


        trace("XML file did not Load");

    }
};


newsXML.load("http://feeds2.oddsmaker.com/jackpots.xml");


Can anyone see whats wrong?
Thanks,
Brandon
User is offlineProfile CardPM
+Quote Post

ahmad_511

RE: XML Add A Comma Into A Number

26 May, 2009 - 01:11 PM
Post #3

MSX
Group Icon

Joined: 28 Apr, 2007
Posts: 509



Thanked: 36 times
Dream Kudos: 500
My Contributions
hello,
AS

var newsXML:XML = new XML();
newsXML.ignoreWhite = true;

var output:String = "";

newsXML.onLoad = function(success) {
if (success) {

var news:Array = newsXML.firstChild.childNodes;
output = news[0].childNodes[0].nodeValue;
trace(output);
badText.text = output;


var count=0
var temp=""
for (var i:Number = output.length-1; i>=0; i--) {

count++;
temp = output.charAt(i) +temp;
if ((count%3 == 0) && (i-1>=0)) {
temp = ","+temp;
}
}
badText.text = temp
} else {


trace("XML file did not Load");

}
};


newsXML.load("http://feeds2.oddsmaker.com/jackpots.xml");

User is offlineProfile CardPM
+Quote Post

bmcc81

RE: XML Add A Comma Into A Number

27 May, 2009 - 06:10 AM
Post #4

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Hmm, Thanks ahmad_511, but...

Doesn't work, also it need: The ( ; ) Cause it wouldn't work.

CODE

var count = 0;
var temp = "";


I don't get it still anyone with the write idea and an explanantion would be great!!!

Is charAt the right built in function?

Anyways, insight is welcomed.

Thanks again,
bmcc
User is offlineProfile CardPM
+Quote Post

ahmad_511

RE: XML Add A Comma Into A Number

27 May, 2009 - 09:27 AM
Post #5

MSX
Group Icon

Joined: 28 Apr, 2007
Posts: 509



Thanked: 36 times
Dream Kudos: 500
My Contributions
Yes, you're right.
first we have to separate the number parts(before and after the(.) )
then apply your procedure

AS

var newsXML:XML = new XML();
newsXML.ignoreWhite = true;

var output:String = "";

newsXML.onLoad = function(success) {
if (success) {

var news:Array = newsXML.firstChild.childNodes;
output = news[0].childNodes[0].nodeValue;
trace(output);
badText.text = output;


var count=0;
var temp="";
var fix=output.toString().split(".");

for (var i:Number = fix[0].length-1; i>=0; i--) {

count++;
temp = fix[0].charAt(i) +temp;
if ((count%3 == 0) && (i-1>=0)) {
temp = ","+temp;
}
}
badText.text = temp+"."+fix[1];
} else {


trace("XML file did not Load");

}
};


newsXML.load("http://feeds2.oddsmaker.com/jackpots.xml");


This post has been edited by ahmad_511: 27 May, 2009 - 09:30 AM
User is offlineProfile CardPM
+Quote Post

bmcc81

RE: XML Add A Comma Into A Number

27 May, 2009 - 12:20 PM
Post #6

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Hi ahmad_511,

I tried what you said, but I still get no decimal point in my number. Is there something missing.

Also I would like it very much if you could explain a little more. I'm trying to follow but am having problems.

Thank alot,
Bmcc81
User is offlineProfile CardPM
+Quote Post

bmcc81

RE: XML Add A Comma Into A Number

28 May, 2009 - 05:00 AM
Post #7

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Ah, I finally figured it out.

I guess I just needed a fresh set of eyes, the doing code the next morning always helps me see the problem. I guess I get a little frustrated.


So the solution was to turn off the initial output and let the answer come out of the code that ahmad_511 wrote smile.gif

I also added a "$" to the begining of the data.

So here it is and works great!!!


CODE
var newsXML:XML = new XML();
newsXML.ignoreWhite = true;
var output:String = "";
newsXML.onLoad = function(success) {
    if (success) {
        var news:Array = newsXML.firstChild.childNodes;
        output = news[0].childNodes[0].nodeValue;
        trace(output);
        //badText.text = output;
        var count = 0;
        var temp = "";
        var fix = output.toString().split(".");
        for (var i:Number = fix[0].length-1; i>=0; i--) {
            count++;
            temp = fix[0].charAt(i)+temp;
            if ((count%3 == 0) && (i-1>=0)) {
                temp = ","+temp;
            }
        }
        badText.text = "$"+temp+"."+fix[1];   // This is what gives you the excellent data
        //trace(badText);
    } else {
        trace("XML file did not Load");
    }
};
newsXML.load("http://feeds2.oddsmaker.com/jackpots.xml");


Thanks a bunch ahmad_511,
Bmcc81



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:05AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month