[Flutter Dart] 세 자리마다 쉼표로 구분하여 숫자를 표시합니다.
개시하다
금액 단위를 표시하기 위해 사용하는 물건입니다.
이번엔 넘버포머를 이용했어요.
NumberFormat class - intl library - Dart API
import
import 'package:intl/intl.dart';
쉼표로 세 자리를 나누다
final formatter = NumberFormat("#,###.0");
var result = formatter.format(50101214);
print(result); // 50,101,214
세 자리 구분자 최대 한 자리 소수점
금액 단위를 표시하고 싶을 때
final formatter = NumberFormat("#,###.0");
var value = (50101214 / 10000);
var result = formatter.format(value);
print(result+'万円'); //5,010.1万円
세 자리 구분자 최대 두 자리
final formatter = NumberFormat("#,###.0#");
var value = (50101214 / 10000);
var result = formatter.format(value);
print(result+'万円'); //5,010.12万円
다른 문법이 있다면 메시지를 남겨주세요.String도 지원됩니다.
이쪽 기사를 참고하게 해 주세요.
Function mathFunc = (Match match) => '${match[1]},';
RegExp reg = RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))');
String result = '20000円'.replaceAllMapped(reg, mathFunc);
print('$result');//20,000円
Reference
이 문제에 관하여([Flutter Dart] 세 자리마다 쉼표로 구분하여 숫자를 표시합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/mcz9mm/articles/8408c2441c898b95429c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)