Klovis Posted July 18, 2011 Posted July 18, 2011 (edited) I have this data coming to me in a tcp connection and i need it to be a simple number with no letters or 'e's so how would I make this string into a float 9.426686e+010 the data is a form of scientific notation Edited July 18, 2011 by Klovis
sigil Posted July 18, 2011 Posted July 18, 2011 (edited) You can use _WinAPI_FloatToInt(). Edited July 18, 2011 by sigil
MvGulik Posted July 18, 2011 Posted July 18, 2011 (edited) You can use _WinAPI_FloatToInt(). Its how to make a number in "string" form into a real Number() value. Edited July 18, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
MvGulik Posted July 18, 2011 Posted July 18, 2011 (edited) So, the winApi thing wont work?Depends on what your looking for. As you mentioned Float. And that winapi function is returning a Int. I don't think it will work for what you have in mind.---Think I better quote myself with a little adjustment.... real Number() value. Edited July 18, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
sigil Posted July 18, 2011 Posted July 18, 2011 (edited) Klovis, can you give an example of a string you would get from the tcp connection and what you would want it to return? e.g., input: "3.552e+05" output: 355200 Edited July 18, 2011 by sigil
ProgAndy Posted July 18, 2011 Posted July 18, 2011 (edited) ... MsgBox(0, '', Number("9.426686e+010")) Edited July 18, 2011 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
MvGulik Posted July 18, 2011 Posted July 18, 2011 Well, if where going to post code ... #include <winapi.au3> main() Func main() Local $str = '9.426686e+010' DebugOut('$str', $str) ;### Debug DebugOut. ;; $str = "9.426686e+010" Local $num = Number($str) DebugOut('$num', $num) ;### Debug DebugOut. ;; $num = 94266860000 {Double} Local $wapi = _WinAPI_FloatToInt($str) DebugOut('$wapi', $wapi) ;### Debug DebugOut. ;; $wapi = 2139095040 {Int64} EndFunc Func DebugOut($sMsg='',$vData='!NuLL!',$iErr=@error,$iExt=@extended,$iLine=@ScriptLineNumber) If Not(String($vData)=='!NuLL!')Then If IsString($vData)Then If $vData Then $sMsg&=' = '&'"'&$vData&'"' ;; StringReplace($vData,'"','""',0,1) Else $sMsg&=' = '&'{EmptyString}' EndIf Else $sMsg&=' = '&String($vData)&' {'&VarGetType($vData)&'}' EndIf EndIf If $iErr Or $iExt Then $sMsg='['&$iErr&','&$iExt&']('&$iLine&',) '&$sMsg Return SetError($iErr,$iExt,ConsoleWrite($sMsg&@CRLF)) EndFunc "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
jaberwacky Posted July 19, 2011 Posted July 19, 2011 Thanks guys got the answer!Maybe because it was given to you? Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
wolf9228 Posted July 19, 2011 Posted July 19, 2011 (edited) I have this data coming to me in a tcp connection and i need it to be a simple number with no letters or 'e's so how would I make this string into a float 9.426686e+010 the data is a form of scientific notation int sscanf ( const char * str, const char * format, ...); Read formatted data from string http://www.cplusplus.com/reference/clibrary/cstdio/sscanf/ http://msdn.microsoft.com/en-us/library/zkx076cy.aspx $RT = sscanf("9.426686e+010","%f","float") if Not @error Then MsgBox(0,"",$RT) Func sscanf($Str,$Singleformat,$OutDataType) $RT = DllCall("msvcrt.dll","int:cdecl","sscanf","str",$Str,"str",$Singleformat,$OutDataType & "*",0) if @error Then Return SetError(1,0,0) Return SetError($RT[0] == 0,0,$RT[3]) EndFunc Edited July 19, 2011 by wolf9228 صرح السماء كان هنا
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now