Top

Commas


BYOND Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Aug 31, 2009
Last Updated  Aug 31, 2009
Tags  adding  commas  numbers  to 

Introduction

Ever wanted to add commas to your numbers. Say you got 100000 as a displaying number and you want to convert it to 100,000? Here's the code.

Grab the Code

proc/applycommas(number)
	number=num2text(number,1000000)
	var/digits=length(number)
	var/remaining=0
	var/returnnumber
	while(digits>=1)
		if(digits>3)
			var/end=","+copytext(number,digits-2,digits+1)
			var/get=end
			returnnumber=get+returnnumber
			remaining=(length(get)-1)+remaining
			digits-=3
		else
			var/get=copytext(number,1,(length(number)+1)-remaining)
			returnnumber=get+returnnumber
			digits=0
	return returnnumber

Comments

  (0)  RSS

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom