Put the separator every thousands
조회 수: 8 (최근 30일)
이전 댓글 표시
T=100000000;
T1 = regexprep(string(T),'(\d+)(\d{3})$',"$1'$2")
I would like to have the thousands separator for every 1000
the correct result would be:
1'000'000'000
댓글 수: 2
Stephen23
2024년 2월 10일
편집: Stephen23
2024년 2월 10일
"the correct result would be: 1'000'000'000"
Why should the "correct result" be one billion when the input value is only one hundred million?
100000000 % your input value
1000000000 % your "correct result" with quotes removed
Your "correct result" is ten times larger than the input value: is that intentional or is it ... incorrect ?
채택된 답변
추가 답변 (1개)
Image Analyst
2024년 2월 10일
I use the attached function I wrote. Adapt as needed, like change commas to apostrophes if you want.
댓글 수: 2
Image Analyst
2024년 2월 11일
@Stephen23 thanks for pointing that out. I've corrected it to properly handle cases where the input is negative or a string or a character array instead of a number (double, etc.). New code is attached.
It's definitely more lines than your one liner regexp though. However I'm not as adept with regexp as you -- I never would have figured out that cryptic sequence of regexp characters as you did.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!