IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   HTML/CSS/JavaScript (https://www.ircforumlari.net/html-css-javascript/)
-   -   javascript sayıları formatlamak (https://www.ircforumlari.net/html-css-javascript/624889-javascript-sayilari-formatlamak.html)

hAte 09 Ekim 2014 04:37

javascript sayıları formatlamak
 
/**
*
*
*
* örnek uygulamalar:
* format(12345.6789); //12345,67
* format(12345.6789, {point:'.'}); //12345.67
* format(12345.6789,{suffix:'€'}); //12345,67€
* format(12345.6789,{point:'.',prefix:'$ '}); //$ 12345.67
*/
var format = function(num, options)) {
options.point=options.point||',';
options.group=options.group||' ';
options.places=options.places||2;
options.suffix=options.suffix||'';
options.prefix=options.prefix||'';

regex = /(\d+)(\d{3})/;
result = ((isNaN(num) ? 0 : Math.abs(num)).toFixed(options.places)) + '';

for (result = result.replace('.', options.point); regex.test(result) && options.group; result=result.replace(regex, '$1'+options.group+'$2')) {};
return (num < 0 ? '-' : '') + options.prefix + result + options.suffix;
};


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 01:24.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk