¾È³çÇϼ¼¿ä HappyCGI ÀÔ´Ï´Ù. ^^*
¿©·¯ºÐ Javascript ·Î ±Ý¾×°è»êÇÏ¿© ȯ»êÇϰųª ÇÒ¶§ , ·Î ±Ý¾× ±¸ºÐÁþ±â ³Ê¹« ºÒÆíÇϽÃÁÒ?
Àúµµ ¸¹ÀÌ ºÒÆíÇØ¿ä..¤Ì¤Ì PHP ¿¡¼´Â number_format ÇÔ¼ö·Î ½±°Ô ½±°Ô ÇÒ¼ö ÀÖÁö¸¸ Javascript ¿¡´Â ¾ø´õ¶ó±¸¿ä.
±×·¡¼ ¸¸µé¾î º¸¾Ò½À´Ï´Ù. ^^
±âº»»ç¿ë¹ýÀº PHP ÀÇ number_format °ú °°½À´Ï´Ù.
¼Ò½ºÃ·ºÎ ÇÕ´Ï´Ù. ^^
<script type="text/javascript">
<!--
function number_format(numstr,cut_comma)
{
if(typeof(numstr) == 'string')
{
numstr = parseFloat(numstr);
}
var numstr = numstr.toFixed(cut_comma);
numstr_arr = numstr.split('.');
if(cut_comma == 0 || cut_comma == undefined)
{
return splitComma(numstr_arr[0]);
}
else
{
numstr_comma = numstr_arr[1].substr(0,cut_comma);
return splitComma(numstr_arr[0])+"."+numstr_comma;
}
}
function splitComma(str) {
if (isNaN(str) || str == "") {
return "";
} else {
str = str - 0;
var txtNumber = String(str);
var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
var arrNumber = txtNumber.split('.');
arrNumber[0] += '.';
do
{
arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
} while (rxSplit.test(arrNumber[0]));
if (arrNumber.length > 1) {
return arrNumber.join('');
}else
{
return arrNumber[0].split('.')[0];
}
}
}
function test()
{
number = document.getElementById("frm").number.value;
cut_comma = document.getElementById("frm").cut_comma.value;
tmp = number_format(number,cut_comma);
document.getElementById("frm").result.value = tmp;
}
//-->
</script>
<form name="frm">
<pre>
Number_Format ÇÔ¼ö¸¦ ½ÇÇà½ÃÄÑ º¾½Ã´Ù. ^^
Number_Format( <input type='text' name='number' value='' size='7'>,<input type='text' name='cut_comma' size='1'> ) <input type='button' value='½ÇÇàÇϱâ' onClick="test();">
---------- ½ÇÇà°á°ú º¸±â ----------
<textarea name='result' value='' style='width:300px; height:80px;'></textarea>
</pre>
</form>
|