hack ¤Î¤¿¤á¤Î¥Í¥¿Ä¢, etc,,,

Thousands Separator ¤È¸À¤¦¤«¡¢¤¤¤ï¤æ¤ë 3 ·å¶èÀÚ¤ê¤È¤« 1,000 ¶èÀÚ¤ê¤È¤«Àé¤Î°Ì¤Î¥³¥ó¥Þ¤È¸À¤¦¤«¡¢°Ì¼è¤ê¤È¸À¤¦¤«

printf

SUSv2 ¤ËÂбþ¤·¤Æ¤ë¤È flag ¤Ë ' ¤òÍ¿¤¨¤ë¤È·å¶èÀڤꤷ¤Æ¤¯¤ì¤ëÌÏÍÍ¡£
printf("%'d", 1234567890);

Cygwin ¤ä Ubuntu ¤Ç³Îǧ¤·¤¿ÈϰϤÀ¤È bash ¤Ï¤³¤ì¤Ë³ºÅö¤¹¤ë¤¬¡¢C/C++ ¤Ï³ºÅö¤·¤Æ¤Ê¤¤¤è¤¦¤À¡£
2010-12-07 ¸½ºß Ubuntu 10.04 ¤Ç³Îǧ¤¹¤ë¸Â¤ê¤Ë¤ª¤¤¤Æ Ruby 1.8.7 ¤Î format ¤Ç¤Ï SUSv2 ¤Î flag ¤Ë¤ÏÂбþ½ÐÍè¤Æ¤Ê¤¤ÌÏÍÍ
´Ø¿ô¤Ç¤ä¤ë¤È¤³¤ó¤Ê´¶¤¸¤«¡©
def ts x; x.to_s =~ /^([^.]*\d)(\d{3}(\.|$))/ ? x = ts($1)+","+$2+$' : x; end

´ØÏ¢

Ruby ÈǤΥǥåɥ³¥Ô¡¼¤À¤±¤É¤³¤ó¤Ê´¶¤¸¤«¡©
function ts(x){
  var y,z;
  return x.toString().match(/^([^.]*\d)(\d{3}(\.|$))/)
    ? (y = RegExp.$2, z = RegExp.rightContext, x = ts(RegExp.$1) + "," + y + z)
    : x;
}
ºÆµ¢¤¹¤ë¤È RegExp ¤¬¾å½ñ¤­¤µ¤ì¤ë¤Î¤Ç¡¢·×»»½ç½ø¤ËÃí°Õ¤·¤Ê¤¬¤é¼ã´³¹©Éפ¹¤ëɬÍפ¬¤¢¤ë¤ß¤¿¤¤¡£
std::ostringstream ¤Ë std::locale ¿©¤ï¤»¤ë¤ÈÎɤ¤¤é¤·¤¤¡£
¿ʬ¤³¤ó¤Ê´¶¤¸¡£
#include <string>
#include <sstream>
#include <locale>
template<class T> inline const std::string ts(T v)
{
  std::ostringstream oss;
  oss.imbue(std::locale(""));
  oss << std::fixed << v;
  return oss.str();
}

»²¹Í:
Äɵ­: 2018-10-15
Cygwin ¤À¤È libstdc++ ¤Î¥³¥ó¥Ñ¥¤¥ë¥ª¥×¥·¥ç¥ó¤¬Éå¤Ã¤Æ¤ë¤é¤·¤¯ std::locale ¤¬ "C" ¤È "POSIX" °Ê³°¿©¤ï¤»¤ë¤È runtime_exception ÅǤ¯¤Î¤Ç¡¢¸½»þÅÀ¤Ç¤³¤ÎÊýË¡¤Ï»È¤¨¤Ê¤¤ÌÏÍÍ¡£
´ØÏ¢:
String::Format Method ¤ò»È¤¦¤È Excel ¤Î½ñ¼°»ØÄê¤ÈƱ¤¸Êý¼°¤Ç½ÐÍè¤ë¤è¤¦¤À¡£
  • MSDN Library / NET Development / .NET Framework 4.6 and 4.5 / Development Guide / Application Essentials / Base Types / Formatting Types / Custom Numeric Format Strings # The "," Custom Specifier
¤³¤ì¤Ï VB ¤È¤« VBA ͳÍ褫¤Ê¡©
C++ ¤Ç¤â CLR ¤Ç¥³¥ó¥Ñ¥¤¥ë¤¹¤ë¤È»È¤¨¤ë¤Ã¤Ý¤¤¤±¤É¡£
¡Ö½ñ¼°»ØÄê¥ß¥Ë¸À¸ì»ÅÍÍ¡×¤Ë grouping_option ::= "_" | "," ¤¬¤¢¤ë¤Î¤Ç¡¢format() ¤ò»È¤Ã¤Æ¡¢°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¤È "," ¤Þ¤¿¤Ï "_" ¤Ç·å¶èÀÚ¤ê½ÐÍè¤ë¡£
a = 123456789
format(a, ",") # or format(a, "_")
Python 3.6 ¤ÇƳÆþ¤µ¤ì¤¿¡Ö¥Õ¥©¡¼¥Þ¥Ã¥ÈºÑ¤ßʸ»úÎó¥ê¥Æ¥é¥ë¡×¤òÍѤ¤¤ë¤È¡¢°Ê²¼¤Î¤è¤¦¤Ë½ñ¤¯¤³¤È¤â½ÐÍè¤ë¡£
a = 123456789
f'{a:,}' # or f'{a:_}'
¤Þ¤¿¡¢¡Ö¿ôÃÍ¥ê¥Æ¥é¥ë¡×¤Ç¤ÏÀ°¿ô¡¢ÉâÆ°¾®¿ôÅÀ¿ô¶¦¤Ë "_" ¤¬·å¶èÀÚ¤êʸ»ú¤È¤·¤Æ̵»ë¤µ¤ì¤ë¤Î¤Ç¡¢°Ê²¼¤Î¤è¤¦¤Ë¿ô»ú¤Î´Ö¤ÎǤ°Õ¤Î°ÌÃ֤˽ñ¤¯¤³¤È¤¬¤Ç¤­¤ë¡£
a = 1_23_456_7890

»²¹Í:

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

WikiÆ⸡º÷

¥Õ¥ê¡¼¥¨¥ê¥¢

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹