![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2007
Posts: 4
Rep Power: 0
![]() |
Sum of digits in a float?
Hey everyone,
Simple - what's a nice way to count the sum of digits in a floating point number (e.g. 176.3)? Is there a function similar to atoi and itoa but for floats? EDIT: Actually, I'm more interested in converting float to ASCII, summing up digits is the next step. Thanks in advance! Last edited by maligree; Jul 12th, 2008 at 10:10 AM. |
|
|
|
|
|
#2 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 310
Rep Power: 4
![]() |
Re: Sum of digits in a float?
One way to convert a float to a string is to use std::stringstream.
Something like this: float x = 1.0f; std::stringstream theString; theString << x; const char* result = theString.str().c_str(); EDIT: Oops, this was in the C forum not in C++. std::stringstream is only available in C++. Sorry...
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 225
Rep Power: 3
![]() |
Re: Sum of digits in a float?
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2007
Posts: 4
Rep Power: 0
![]() |
Re: Sum of digits in a float?
Ah, thanks a lot.. it seems painfully obvious now.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Slight Float Problem. Code and Screenshot. | brokenhope | HTML / XHTML / CSS | 0 | Nov 27th, 2007 5:31 PM |
| counting digits | rwm | C++ | 25 | Apr 11th, 2007 8:16 AM |
| set a number to 2 digits only | hipolito | C | 24 | Jul 17th, 2006 4:47 PM |
| Two ints divided into a float. | Dygear | C++ | 2 | Apr 1st, 2005 6:42 PM |
| float precision and MFC... | Racine_ | C++ | 0 | Feb 5th, 2005 9:31 AM |