converting numbers to strings and back
Daniel Keep
daniel.keep.lists at gmail.com
Fri Oct 5 21:33:20 PDT 2007
dominik wrote:
> I was trying, for fun and learning, to do some PHP style trash programming.
> Basically, I wanted to convert float to string, and string back to float. I
> did make it work, but not as documentation said I should. Look at the
> commented out line in example I made.
>
> I'm trying to learn D (I'm coming from HEAVY C and PHP background), so I
> occasionally post questions which might seem retarded. I'm sorry, and thank
> you for your patience and help :)
>
> Documentation for D is still pretty sparse on the interwebtubes - luckly
> this newsgroup is pretty active and helpfull. Is there a place where D
> documentation is centralized? Like php.net for PHP for example - which I
> find the most usefull documentation formats for any language (including
> standard library) I've been working with. I have found several places on
> net, but none seem to be active and/or full of information. I'd like to
> contribute as I'm learning, so others can find more information easily.
>
> --------------------------------------------
> import std.stdio;
> import std.string;
> import std.conv;
>
> void main(char[][] args) {
>
> float fFloat = 214.4;
> float fBack = 0;
>
> char[] cTest = std.string.toString(fFloat);
> writefln(cTest);
>
> // fBack = to!(float)(cTest); // this does not work! Why?
> fBack = toFloat(cTest);
> // This does work, but docs say it will be deprecated
> // because to!(T) supercedes it.
> writefln(fBack);
>
> }
> --------------------------------------------
Using my tinfoil telepathy hat, I suspect you are... using a 1.x series
compiler, which does not have the std.conv.to!(T) template. You'll need
to either use D 2.0 for that, or just use toFloat.
If you *are* using a 2.x series compiler, then we've got a problem :)
-- Daniel
More information about the Digitalmars-d-learn
mailing list