Advertisement
aokmikey

String to float

Nov 25th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. // Stolen from bo2 I can code better than this but
  2. // i can not be asked to make it.
  3. // Thanks 3ark. I still hate you :) <3
  4. string_to_float( string )
  5. {
  6.     floatparts = strtok( string, "." );
  7.     if ( floatparts.size == 1 )
  8.     {
  9.         return int( floatparts[ 0 ] );
  10.     }
  11.     whole = int( floatparts[ 0 ] );
  12.     decimal = 0;
  13.     i = floatparts[ 1 ].size - 1;
  14.     while ( i >= 0 )
  15.     {
  16.         decimal = ( decimal / 10 ) + ( int( floatparts[ 1 ][ i ] ) / 10 );
  17.         i--;
  18.  
  19.     }
  20.     if ( whole >= 0 )
  21.     {
  22.         return whole + decimal;
  23.     }
  24.     else
  25.     {
  26.         return whole - decimal;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement