Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:45:22+00:00 2026-06-14T16:45:22+00:00

I would like to turn a number into a string using a comma as

  • 0

I would like to turn a number into a string using a comma as a thousands separator. Something like:

x = 120501231.21;
str = sprintf('%0.0f', x);

but with the effect

str = '120,501,231.21' 

If the built-in fprintf/sprintf can’t do it, I imagine cool solution could be made using regular expressions, perhaps by calling Java (which I assume has some locale-based formatter), or with a basic string-insertion operation. However, I’m not an expert in either Matlab regexp’s or calling Java from Matlab.

Related question: How can I print a float with thousands separators in Python?

Is there any established way to do this in Matlab?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:45:23+00:00Added an answer on June 14, 2026 at 4:45 pm

    One way to format numbers with thousands separators is to call the Java locale-aware formatter. The “formatting numbers” article at the “Undocumented Matlab” blog explains how to do this:

    >> nf = java.text.DecimalFormat;
    >> str = char(nf.format(1234567.890123))
    
    str =
    
    1,234,567.89     
    

    where the char(…) converts the Java string to a Matlab string.

    voilà!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you change this: a-10-b-19-c into something like this: a-10-b-20-c using regular expressions
I would like to turn this query to regular inline sql without using stored
I'm using the Django ORM in a non-Django application and would like to turn
Using ffmpeg I can take a number of still images and turn them into
I would like to turn off the dropdown PhoneHelp if phone is selected in
I am getting expected notices and warnings and would like to turn them off
I have the following shortcode. What I would like to do is turn this
I would like to embed Clojure code into Java. This site was helpful in
unfortunately I was never good with math but I would like to know how
Is there a way to do something like lexical closures using macrolet? What I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.