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 485989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:27:27+00:00 2026-05-13T01:27:27+00:00

I have an array of floats where data are stored with varying decimal points

  • 0

I have an array of floats where data are stored with varying decimal points so some are 123.40000, 123.45000, 123.45600…now if i want to print these values in the string without the 0s in the end in printf() so that they are 123.4, 123.45, 123.456, without those 0s in the end. Is this possible? If so, how?

  • 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-05-13T01:27:28+00:00Added an answer on May 13, 2026 at 1:27 am

    Use the %g formatter:

    printf( "%g", 123.4000 );
    

    prints

    123.4

    Trailing zeros are removed, but unfortunately so is the trailing decimal point if the fractional part is zero. I don’t know if there is actually any way of doing what you want directly using printf() – I think something like this is probably your best bet:

    #include <stdio.h>
    #include <math.h>
    
    void print( FILE * f, double d ) {
        if ( d - floor(d) == 0.0 ) {
            fprintf( f, "%g.", d );
        }
        else {
            fprintf( f, "%g", d );
        }
    }
    
    int main() {
        print( stdout, 12.0 );
        print( stdout, 12.300 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran some CUDA code that updated an array of floats. I have a
I have some Thread count pCount and I have some float[] array. I want
I have array of strings, String[] data and it's 10 elements has value P
I have some classes that need a bunch of data tables to do their
I have an elevation map represented by a 2D array of floats. There are
I have been given some 'reports' from another piece of software that contains data
Using C++ and .net I have a stream of data I want to display
I want my flot graph to update it's data on set intervals. I have
I have a property list ( Data.plist ) that contains an array of two
I am storing some data (some floats, some strings) to a plist and then

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.