ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingใครเก่ง php กะ javascript เข้ามาช่วยหน่อยครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ใครเก่ง php กะ javascript เข้ามาช่วยหน่อยครับ  (อ่าน 7333 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
Soisiamdotcom
คนรักเสียว
*

พลังน้ำใจ: 39
ออฟไลน์ ออฟไลน์

กระทู้: 174



ดูรายละเอียด เว็บไซต์
« เมื่อ: 21 พฤศจิกายน 2012, 23:56:48 »

อยากจะให้ช่วยเขียนฟังชั่นphpนี้เป็น javascript หน่อยครับ

โค๊ด:
function mksize($bytes)
{
if ($bytes < 1000 * 1024)
return number_format($bytes / 1024, 2) . " kB";
elseif ($bytes < 1000 * 1048576)
return number_format($bytes / 1048576, 2) . " MB";
elseif ($bytes < 1000 * 1073741824)
return number_format($bytes / 1073741824, 2) . " GB";
else
return number_format($bytes / 1099511627776, 2) . " TB";
}
บันทึกการเข้า
ohmohm
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 170
ออฟไลน์ ออฟไลน์

กระทู้: 3,098



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 22 พฤศจิกายน 2012, 12:26:11 »

ส่วนตัวไม่ได้เก่งมากมายนะครับ แต่ขอแนะนำ
http://phpjs.org/functions/number_format/
บันทึกการเข้า
kobkung
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 103
ออฟไลน์ ออฟไลน์

กระทู้: 1,312



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 22 พฤศจิกายน 2012, 13:16:19 »

ส่วนตัวไม่ได้เก่งมากมายนะครับ แต่ขอแนะนำ
http://phpjs.org/functions/number_format/


อย่าเชื่อ คนเนี้ยเก่งครับ  wanwan004 เห็นมาหลายทู้ละ แน่นนะ
บันทึกการเข้า

เราเป็นบริษัท รับทำเว็บไซต์ แก้เว็บเดิม เขียน Php+Mysql+jQuery+css+bootstrap  งานตามสั่ง ประสบการณ์ จะ 19 ปี ละจ้า
Smilephp.com รับทำเว็บไซต์บริษัท e-commerce + ระบบชำระเงิน paypal,ธนาคาร  เว็บบริษัท เว็บขายของ ระบบจอง เช่า เขียน PHP ได้ทุกแนว  ช่วงนี้เน้นรับงาน ERP ระบบเอกสารบริษัท ,บัญชี ,  Barcode, Stock , Warehouse , Logistic ติดต่อ 086-364-5262

งดตอบคนทำเว็บนอกลู่นอกทาง ไม่ทำเว็บ WP ปั่นแชร์ เว็บประมูล สคริปปั่นใดๆ ไม่ทำเว็บบอลและพ
marus
ก๊วนเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 467



ดูรายละเอียด
« ตอบ #3 เมื่อ: 22 พฤศจิกายน 2012, 15:44:11 »

โค๊ด:
function mksize($bytes)
{
    if ($bytes < 1000 * 1024){
        return number_format($bytes / 1024, 2) + " kB";
    }else if ($bytes < 1000 * 1048576){
        return number_format($bytes / 1048576, 2) + " MB";
    }else if ($bytes < 1000 * 1073741824){
        return number_format($bytes / 1073741824, 2) + " GB";
    }else{
        return number_format($bytes / 1099511627776, 2) + " TB";
    }
}

function number_format (number, decimals, dec_point, thousands_sep) {
  // http://kevin.vanzonneveld.net
  // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +     bugfix by: Michael White (http://getsprink.com)
  // +     bugfix by: Benjamin Lupton
  // +     bugfix by: Allan Jensen (http://www.winternet.no)
  // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +     bugfix by: Howard Yeend
  // +    revised by: Luke Smith (http://lucassmith.name)
  // +     bugfix by: Diogo Resende
  // +     bugfix by: Rival
  // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
  // +   improved by: davook
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Jay Klehr
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Amir Habibi (http://www.residence-mixte.com/)
  // +     bugfix by: Brett Zamir (http://brett-zamir.me)
  // +   improved by: Theriault
  // +      input by: Amirouche
  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // *     example 1: number_format(1234.56);
  // *     returns 1: '1,235'
  // *     example 2: number_format(1234.56, 2, ',', ' ');
  // *     returns 2: '1 234,56'
  // *     example 3: number_format(1234.5678, 2, '.', '');
  // *     returns 3: '1234.57'
  // *     example 4: number_format(67, 2, ',', '.');
  // *     returns 4: '67,00'
  // *     example 5: number_format(1000);
  // *     returns 5: '1,000'
  // *     example 6: number_format(67.311, 2);
  // *     returns 6: '67.31'
  // *     example 7: number_format(1000.55, 1);
  // *     returns 7: '1,000.6'
  // *     example 8: number_format(67000, 5, ',', '.');
  // *     returns 8: '67.000,00000'
  // *     example 9: number_format(0.9, 0);
  // *     returns 9: '1'
  // *    example 10: number_format('1.20', 2);
  // *    returns 10: '1.20'
  // *    example 11: number_format('1.20', 4);
  // *    returns 11: '1.2000'
  // *    example 12: number_format('1.2000', 3);
  // *    returns 12: '1.200'
  // *    example 13: number_format('1 000,50', 2, '.', ' ');
  // *    returns 13: '100 050.00'
  // Strip all characters but numerical ones.
  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  var n = !isFinite(+number) ? 0 : +number,
    prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
    sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
    dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
    s = '',
    toFixedFix = function (n, prec) {
      var k = Math.pow(10, prec);
      return '' + Math.round(n * k) / k;
    };
  // Fix for IE parseFloat(0.55).toFixed(0) = 0;
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  if (s[0].length > 3) {
    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || '';
    s[1] += new Array(prec - s[1].length + 1).join('0');
  }
  return s.join(dec);
}

alert(mksize(167585));
« แก้ไขครั้งสุดท้าย: 22 พฤศจิกายน 2012, 15:45:50 โดย marus » บันทึกการเข้า
Soisiamdotcom
คนรักเสียว
*

พลังน้ำใจ: 39
ออฟไลน์ ออฟไลน์

กระทู้: 174



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 22 พฤศจิกายน 2012, 16:54:42 »

โค๊ด:
function mksize($bytes)
{
    if ($bytes < 1000 * 1024){
        return number_format($bytes / 1024, 2) + " kB";
    }else if ($bytes < 1000 * 1048576){
        return number_format($bytes / 1048576, 2) + " MB";
    }else if ($bytes < 1000 * 1073741824){
        return number_format($bytes / 1073741824, 2) + " GB";
    }else{
        return number_format($bytes / 1099511627776, 2) + " TB";
    }
}

function number_format (number, decimals, dec_point, thousands_sep) {
  // http://kevin.vanzonneveld.net
  // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +     bugfix by: Michael White (http://getsprink.com)
  // +     bugfix by: Benjamin Lupton
  // +     bugfix by: Allan Jensen (http://www.winternet.no)
  // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +     bugfix by: Howard Yeend
  // +    revised by: Luke Smith (http://lucassmith.name)
  // +     bugfix by: Diogo Resende
  // +     bugfix by: Rival
  // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
  // +   improved by: davook
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Jay Klehr
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Amir Habibi (http://www.residence-mixte.com/)
  // +     bugfix by: Brett Zamir (http://brett-zamir.me)
  // +   improved by: Theriault
  // +      input by: Amirouche
  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // *     example 1: number_format(1234.56);
  // *     returns 1: '1,235'
  // *     example 2: number_format(1234.56, 2, ',', ' ');
  // *     returns 2: '1 234,56'
  // *     example 3: number_format(1234.5678, 2, '.', '');
  // *     returns 3: '1234.57'
  // *     example 4: number_format(67, 2, ',', '.');
  // *     returns 4: '67,00'
  // *     example 5: number_format(1000);
  // *     returns 5: '1,000'
  // *     example 6: number_format(67.311, 2);
  // *     returns 6: '67.31'
  // *     example 7: number_format(1000.55, 1);
  // *     returns 7: '1,000.6'
  // *     example 8: number_format(67000, 5, ',', '.');
  // *     returns 8: '67.000,00000'
  // *     example 9: number_format(0.9, 0);
  // *     returns 9: '1'
  // *    example 10: number_format('1.20', 2);
  // *    returns 10: '1.20'
  // *    example 11: number_format('1.20', 4);
  // *    returns 11: '1.2000'
  // *    example 12: number_format('1.2000', 3);
  // *    returns 12: '1.200'
  // *    example 13: number_format('1 000,50', 2, '.', ' ');
  // *    returns 13: '100 050.00'
  // Strip all characters but numerical ones.
  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  var n = !isFinite(+number) ? 0 : +number,
    prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
    sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
    dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
    s = '',
    toFixedFix = function (n, prec) {
      var k = Math.pow(10, prec);
      return '' + Math.round(n * k) / k;
    };
  // Fix for IE parseFloat(0.55).toFixed(0) = 0;
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  if (s[0].length > 3) {
    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || '';
    s[1] += new Array(prec - s[1].length + 1).join('0');
  }
  return s.join(dec);
}

alert(mksize(167585));


ขอบคุณมากครับ
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์