Jump to content

To Add Or Not To Add, A Decimal. That Is The Question.


Recommended Posts

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.

Link to comment
Share on other sites

$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

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

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

$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?
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...