- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: float to string conversion problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 04:37 AM
08-01-2002 04:37 AM
float to string conversion problem
#include
int main()
{
float num = 10.55164516854;
char s[80];
sprintf(s, "%10.10f", num); /* write the double to a string */
printf("Here is the result: %s\n", s);
return 0;
}
Result: Here is the result: 10.0000000000
but should be 10.5516451685
Many thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 04:49 AM
08-01-2002 04:49 AM
Re: float to string conversion problem
What is the compiler ?
I treid this program and it worked fine with cc (the K&R from HP , not the Ansi) and with gcc.
Any options with cc ? What version of HPUX ? of cc/gcc ?
hope that help
Benoit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 04:59 AM
08-01-2002 04:59 AM
Re: float to string conversion problem
Might be your compiler is not supporting this option of string to float conversion.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:02 AM
08-01-2002 05:02 AM
Re: float to string conversion problem
HP-UX 11.00 - C/ANSIC - cc with no option, but you can easily add some.
Bye
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:27 AM
08-01-2002 05:27 AM
Re: float to string conversion problem
I made the test on a linux, it's OK also. That's very strange.
You can try with gcc (install it on your HP-UX, it's available on many portal center), don't forget binutils.
You can also try with a double instead of a float...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 06:05 AM
08-01-2002 06:05 AM
Re: float to string conversion problem
cc -Ac +r myfile.c
The result I got was 0.00000000000. It appears that you must be using the +r which inhibits the automatic promotion of float to double when passing arguments (in this case to sprintf). In this context, it makes sense what is happening.
Note: +r may be being set in CCOPTS.
To test if this is the problem, make this change:
sprintf(s,"%10.10f",(double) num);