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

Welcome to Dream.In.Code
Become an Expert!

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




XML get rid of decimal place

 

XML get rid of decimal place, Trying to get ride of decimal

bmcc81

5 Nov, 2009 - 01:41 PM
Post #1

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Hi,

I'm using XML to get show players ranking and points. But I need to get rid of the decimal place, because the user doesn't need to see it. What I've come up with so far is...

The var called fix is the part of the code that I use to get ride of the decimal place. I'm using the decimal fix from code that I used in an old project, but in that project I left 2 decimal places.

I was wondering if someone could re-jog my memory or help explain.

CODE

var objPokerXml1 = new XML();
var arPokerDates1 = new Array();

objPokerXml1.ignoreWhite = true;
objPokerXml1.onLoad = function(success) {
    if (success) {

        var iTotalTournaments1 = objPokerXml1.childNodes[0].childNodes.length;

        for (i=0; i<iTotalTournaments1; i++) {
            var arTempArray = new Array();

            playerName = objPokerXml1.childNodes[0].childNodes[i].attributes.id;
            points = objPokerXml1.childNodes[0].childNodes[i].childNodes[0].firstChild.nodeValue;
            sTempGameType = objPokerXml1.childNodes[0].childNodes[i].childNodes[1].firstChild.nodeValue;
            scoinValue = objPokerXml1.childNodes[0].childNodes[i].childNodes[2].firstChild.nodeValue;


            arTempArray.push(playerName);//0
            arTempArray.push(points);//1
            arTempArray.push(sTempGameType);//2
            arTempArray.push(scoinValue);//3

            arPokerDates1.push(arTempArray);
        }
        fnCreateText();
        trace(objPokerXml1);

        var fix = objPokerXml1.toString().split(".");
        for (var i:Number = fix[2].length-1; i>=0; i--) {
            count++;
            temp = fix[0].charAt(i)+temp;
            if ((count%3 == 0) && (i-1>=0)) {
                temp = ","+temp;
            }
            trace(fix);
        }
    } else {
        myTextFormat = new TextFormat();
        myTextFormat.size = 10;
        tourny_txt.setTextFormat(myTextFormat);
        trace("XML FEED DOWN");
        tourny_txt.text = "XML_DOWN";
        _root.xml_down._visible = true;
    }
};

function fnCreateText() {
    // trace('arr: '+ arPokerDates1);
    this.createTextField('tourny_txt',0,5,0,210,270);

    var myTextFormat:TextFormat = new TextFormat();

    myTextFormat.size = 10;
    myTextFormat.font = "Arial";
    myTextFormat.color = 0xFFFFFF;
    myTextFormat.leading = 2;


    for (i=0; i<arPokerDates1.length; i++) {
        _root.Scolling_text_Jackpots_mc.tourny_txt.text = tourny_txt.text+arPokerDates1[i][1]+'       '+"PLAYER"+'   '+arPokerDates1[i][2]+newline;
        this.tourny_txt.setTextFormat(myTextFormat);
    }
}

objPokerXml1.load('https://csm.softwareadmintoolbox.com/servlet/disco.TopCasinoPlayers?licenseeId=941&startDate=2009-11-01&endDate=2019-11-01&numOfPlayers=10&sortByCategoryId=2');

if (_root.up) {
    this.tourney_text.scroll += 1;
} else if (_root.down_bt_mc) {
    this.tourney_text.scroll -= 1;
}
this.scrollingText_mc.gotoAndPlay(1);


Thanks in advance,
Brandon


Attached File(s)
Attached File  PlayerPosition.zip ( 6.25k ) Number of downloads: 7

User is offlineProfile CardPM
+Quote Post


bmcc81

RE: XML Get Rid Of Decimal Place

6 Nov, 2009 - 12:46 PM
Post #2

D.I.C Regular
***

Joined: 10 Jul, 2007
Posts: 262



Thanked: 1 times
My Contributions
Okay, maybe I'm showing too much. This is the part I need help with.

So, basically I need this to take off 2 decimal places.

CODE
    

var count = 0;
var temp = "";
var fix = arPokerDates1.toString().split(".");
for (var i:Number = fix[2].length-1; i>=0; i--) {
      count++;
      temp = fix[2].charAt(i)+temp;
      if ((count%3 == 0) && (i-1>=0)) {
      temp = ","+temp;
      }
      trace(fix);
}



Can anyone see where I'm going wrong?
User is offlineProfile CardPM
+Quote Post

thehat

RE: XML Get Rid Of Decimal Place

8 Nov, 2009 - 01:57 PM
Post #3

awake ? web();
Group Icon

Joined: 28 Feb, 2008
Posts: 940



Thanked: 99 times
Dream Kudos: 200
My Contributions
If you want to completely remove the decimal place, you can first convert to a number, then use either Math.floor() or Math.round() to remove the decimal place. floor() will always round down, whereas round() will round to the nearest whole number.

If you insist instead on using a string, you can simply use split with the full stop and then take only the first index generated as demonstrated like so:
CODE

var num:Number = 35.76;
var arr:Array = num.toString().split('.');
trace(arr[0]);  //35

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:03PM

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