LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2004, 10:54 AM   #1
cynthia
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Rep: Reputation: 0
string to double


is there a function that translates/ casts a char[] to a double?

Code:
char arr[]= '1.0000';

double x1 = SOME_FUNCTION(arr);
thanks
 
Old 10-11-2004, 11:24 AM   #2
dizzutch
Member
 
Registered: Sep 2004
Location: Worcester, MA USA
Distribution: Debian, Gentoo, Fedora FC2
Posts: 66

Rep: Reputation: 15
not in stdlib that i know of, you can either write your own function using atoi() and typecasting the result to a double in some way, or if you want a built-in function for everything, switch to Java.
 
Old 10-11-2004, 11:43 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Code:
char arr[] = "1.000000";
double num;

num = strtod(arr, NULL);
 
Old 10-11-2004, 03:24 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
And just to add to what itsme86 said... strtod (string to double), strtold (string to long double), and strtof (string to float) are all in stdlib.h, as are strtol (string to long), strtoll (string to long long), strtoul (string to unsigned long), strtoull (string to unsigned long long), ect. ect. ect.
 
Old 10-12-2004, 02:40 AM   #5
cynthia
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
THANKS GUYS
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Double the desktop, not double the fun! bizshop SUSE / openSUSE 3 08-26-2005 12:22 PM
C# trouble converting from string to double. exodist Programming 2 02-23-2004 11:38 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
Float/Double to String? Mega Man X Programming 16 01-03-2004 07:50 PM
java covert double into string iceman47 Programming 10 05-28-2003 10:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration