converting numbers to strings and back

Bill Baxter dnewsgroup at billbaxter.com
Fri Oct 5 21:41:53 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.

Each page of the D documentation has a "Comments" button in the upper 
left corner.  You can put any observations you make about the 
documentation itself there.   For instance often things are not located 
where you think they are -- opApply is not documented on the operator 
overloading page for instance.  In that case put a link from the 
comments page of where you thought it would be to the page where the 
info is actually found.  Also little examples that clarify what the docs 
say are good to put there.

As for writing full fledged standalone tutorials, I think there's a 
place for those on dsource. 
http://www.dsource.org/projects/tutorials/wiki.  It's a wiki you you can 
add your own there.

> 
> --------------------------------------------
> 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);

That's 2.0 docs you're reading there.  Confusing because it's the defaut 
URL and the only indication it's 2.0 is some small text in upper right 
corner of the page.

For 1.0 you need to use toFloat.

--bb


More information about the Digitalmars-d-learn mailing list