XML get rid of decimal place

Trying to get ride of decimal

Page 1 of 1

2 Replies - 2179 Views - Last Post: 08 November 2009 - 02:57 PM

#1 bmcc81  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 312
  • Joined: 10-July 07

XML get rid of decimal place

Posted 05 November 2009 - 02:41 PM

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.

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)



Is This A Good Question/Topic? 0
  • +

Replies To: XML get rid of decimal place

#2 bmcc81  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 312
  • Joined: 10-July 07

Re: XML get rid of decimal place

Posted 06 November 2009 - 01:46 PM

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.

	

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?
Was This Post Helpful? 0
  • +
  • -

#3 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: XML get rid of decimal place

Posted 08 November 2009 - 02:57 PM

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:
var num:Number = 35.76;
var arr:Array = num.toString().split('.');
trace(arr[0]);  //35


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1