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

  • SEARCH
  • Home
  • 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 8845047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:38:30+00:00 2026-06-14T11:38:30+00:00

Ok, I have a char that is a number. How could I convert it

  • 0

Ok, I have a char that is a number. How could I convert it into a double?

char c;

I’ve tried (double)c, but it converts to zero.

Any ideas?

  • 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-14T11:38:32+00:00Added an answer on June 14, 2026 at 11:38 am

    if you have a null terminated string that you wish to convert to double use atof:

    const char *str = "3.14";
    double x = atof(str);
    printf("%f\n", x); //prints 3.140000
    

    If you have a single character, casting should work:

    char c = 'a'; //97 in ASCII
    double x = (double)c; 
    printf("%f\n", x); //prints 97.000000
    

    If the character is zero then it print zeros of course:

    char c = '\0';
    double x = (double)c; 
    printf("%f\n", x); //prints 0.000000
    

    Note: atof and similar functions don’t detect overflows and return zero on error, so there’s no way to know if it failed (not sure if it sets errno), see also Keith’s comments about undefined behaviour for certain values, so the point is you should use strtol for converting from strings to int and strtod for converting to double those have much better error handling:

    const char *str = "3.14";
    double x = strtod(str, NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have extracted a MAC address into a char* array such that each section
I want to convert a single number of bytes, into a file size (that
I have tried to write a simple program that converts numbers to words (i.e
In phpMyAdmin I have a char(32) column that has no default value(ie. Default: None).
We have a DB with a few hundred tables that have a CHAR Code
I have a class User that looks like this: class User { private: char*
I have developed a small view that contains special char like 'é' and when
I have a C-array that looks like this: char hexc[] = { 0x41, 0x80,
I have an array that is like this: unsigned char array[] = {'\xc0', '\x3f',
I have recently made changes in some code that makes a char name field

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.