# Character limit

**URL:** <https://forum.kirupa.com/t/character-limit/20022>\
**Category:** Uncategorized\
**Created:** [May 4, 2003, 4:32am UTC](https://forum.kirupa.com/t/character-limit/20022 "2003-05-04T04:32:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xzyfer](https://avatars.discourse-cdn.com/v4/letter/x/ce73a5/32.png) [@xzyfer](https://forum.kirupa.com/u/xzyfer)\
**Post date:** [May 4, 2003, 4:32am UTC](https://forum.kirupa.com/t/character-limit/20022/1 "2003-05-04T04:32:43Z")

</div>

ive got a dynamic text box… var name c…  
and i got some maths in the as that then send the answer to the dynamic text box c…but i oftenget the chacaters getting cut off…  
is there a wat to limit how many number are displayed useing as without rounding to whole numbers…i need to set a sertai amout of decimal places…thx…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 4, 2003, 5:26am UTC](https://forum.kirupa.com/t/character-limit/20022/2 "2003-05-04T05:26:03Z")

</div>

it’s not that hard… 😉

```auto
// prototype
Number.prototype.limitDecimals = function(decimals) {
	var str, tmp = this.toString(), dIndex = tmp.lastIndexOf(".")+1, index;
	for (index=0; index<dIndex+decimals; index++) str += tmp.charAt(index);
	return str;
};
// usage
Number.limitDecimals(decimals);
// example
myNumber = 7.7777;
trace(myNumber.limitDecimals(2)); // output: 7.77

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 4, 2003, 7:05am UTC](https://forum.kirupa.com/t/character-limit/20022/3 "2003-05-04T07:05:22Z")

</div>

forget about that… as usual, i like the hard way. 😛

```auto
Number.prototype.limitDecimals = function(decimals) {
	this = this.toString().substr(0, this.toString().lastIndexOf(".")+1+decimals);
	return Number(this);
};

```

that’s much better. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 4, 2003, 1:56pm UTC](https://forum.kirupa.com/t/character-limit/20022/4 "2003-05-04T13:56:30Z")

</div>

theres also

```auto

Number.prototype.limitDecimals = function(depth) {
	var factor = Math.pow(10,depth);
	return Math.round(this*factor)/factor;
};

```

which rounds to that decimal and not just chops 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 4, 2003, 2:46pm UTC](https://forum.kirupa.com/t/character-limit/20022/5 "2003-05-04T14:46:08Z")

</div>

interesting… why i didn’t think about that!? 😛

wait!! i know the answer… i’m a rookie. :-\ 😛
