litlmike Posted March 23, 2006 Share Posted March 23, 2006 I have a variable $Input, that will always be a number. That number will either have a decimal place or not. However, that number ALWAYS NEEDS a decimal place. What is the syntax for it? Psuedo Code: If $Input has a "." in it, then Next If $Input does not have a "." then add ".00" to the end of $Input Example User Enters the number '5' Script must change/add '5' to '5.00' Otherwise, if User Enters the number '5.00' Then Continue with script. _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
cdkid Posted March 23, 2006 Share Posted March 23, 2006 $input = InputBox('enter a number', 'moo') if NOT StringInStr($input, ".") Then $input = $input & ".00" EndIf msgbox(0,'',$input) ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 23, 2006 Share Posted March 23, 2006 (edited) HI, not tested: #include<string.au3> $number = "132132135" MsgBox(0,$number, AddPoint($number)) Func AddPoint($n) If StringInStr($n, ".") = 0 Then return _StringInsert($n, ".00", StringLen($n)) Return $n EndFunc Edit: Too late: And maybe a bit to circumstantially :-) So long, Mega Edited March 23, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
SpookMeister Posted March 23, 2006 Share Posted March 23, 2006 (edited) I have a variable $Input, that will always be a number. That number will either have a decimal place or not. However, that number ALWAYS NEEDS a decimal place. What is the syntax for it? Psuedo Code: If $Input has a "." in it, then Next If $Input does not have a "." then add ".00" to the end of $Input Example User Enters the number '5' Script must change/add '5' to '5.00' Otherwise, if User Enters the number '5.00' Then Continue with script.$input = InputBox("get info", "enter a number") if not StringInStr($input,".") then $input = $input & ".00" MsgBox(0,"",$input) Damn boss... asking me questions and making me slow Edited March 23, 2006 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
MHz Posted March 23, 2006 Share Posted March 23, 2006 How about StringFormat to do it. $var = 5 $var = StringFormat('%.2f', $var) MsgBox(0, '', $var) Link to comment Share on other sites More sharing options...
herewasplato Posted March 23, 2006 Share Posted March 23, 2006 $input = InputBox('enter a number', 'moo') $input = StringFormat("%.2f", $input) MsgBox(0, '', $input) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
litlmike Posted March 23, 2006 Author Share Posted March 23, 2006 $input = InputBox('enter a number', 'moo') $input = StringFormat("%.2f", $input) MsgBox(0, '', $input) THanks to everyone for the input! Didn't realize there was so many ways to accomplish this. I tried StringFormat since it seemed shortest, but i notice that it does not add a the decimal if the value is zero. Is there a way to make that happen? _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
GaryFrost Posted March 23, 2006 Share Posted March 23, 2006 THanks to everyone for the input! Didn't realize there was so many ways to accomplish this. I tried StringFormat since it seemed shortest, but i notice that it does not add a the decimal if the value is zero. Is there a way to make that happen? $input = InputBox('enter a number', 'moo') $input = StringFormat("%2.2f", $input) MsgBox(0, '', $input) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
litlmike Posted March 23, 2006 Author Share Posted March 23, 2006 $input = InputBox('enter a number', 'moo') $input = StringFormat("%2.2f", $input) MsgBox(0, '', $input) Actually, StringFormat("%.2f", $input) works. I found that _IEFormElementSetValue() would truncate my variable, unless I did this one little thing beforehand. Thanks everyone! _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
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