WoW:API EditBox GetNumber: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(i just read the type is really number, not float; strange language, this lua ;))
 
m (Move page script moved page API EditBox GetNumber to API EditBox GetNumber without leaving a redirect)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<center>'''GetNumber''' ''-Documentation by DerGhulbus-''</center>
{{widgetmethod}}


number = editBox:GetNumber()
This function reads text entered into the editBox, tries to convert it into a number, and returns corresponding numerical value, or 0 if text didn't look like a number.


If a number was entered, it returns a numerical value of the number. If anything else was entered (including nil) it returns 0.
num = editBox:GetNumber()


----
=== Arguments ===
;''Arguments''
:''none''


''none''
=== Returns ===
----
;''Returns''


:number
:;num: number entered in the EditBox
:;number: Number - corresponding to the number entered in the EditBox


----
=== Details ===
;''Details''


This function proves to be very useful when reading in numbers. While [[API EditBox GetText|GetText()]] will return a string, which you can't perform any arithmetic operations or comparison with, this function converts the TextString to a number. This will even work for all strings that are considered as well formed numerical constants in lua (so it will work for '314.16e-2' too).
This function proves to be very useful when reading in numbers. While [[API EditBox GetText|GetText()]] will return a string, which you can't perform any arithmetic operations or comparison with, this function converts the TextString to a number. This will even work for all strings that are considered as well formed numerical constants in lua (so it will work for '314.16e-2' too).


If you enter a string, or a hybrid like 'abc123def', the function returns 0.
Function will scan editbox text and return once it finds text which cannot be interpreted as part of a number. It will return number ''recognized so far'', or 0 if there were no valid digits recognized. The function will never return '''nil'''. For example (User input => Function returns):
* ":)" => 0
* "123punks! 42" => 123
* "-2.78" => -2.7799999713898
* "+3.15" => 0
* "222e-03" => 0.22200000286102
* "0.31415926536e+1" => 3.1415927410126
* "14e6" => 14000000
* "21,000" => 21


If you enter a hybrid like 12abc34 the function will ignore everything after the last valid digit (thus returning 12 in the example)
== Note ==
 
To verify that a 0 returned is indeed the numerical value in the editbox field, convert the results of '''GetNumber()''' to a string using [[API tostring|tostring()]], and compare to the results of [[API EditBox GetText|GetText()]].
----
{{Template:WoW API}}
[[Category:API Functions|EditBox]]

Latest revision as of 04:45, 15 August 2023

Widget API ← EditBox < GetNumber

This function reads text entered into the editBox, tries to convert it into a number, and returns corresponding numerical value, or 0 if text didn't look like a number.

num = editBox:GetNumber()

Arguments[edit]

none

Returns[edit]

num
number entered in the EditBox

Details[edit]

This function proves to be very useful when reading in numbers. While GetText() will return a string, which you can't perform any arithmetic operations or comparison with, this function converts the TextString to a number. This will even work for all strings that are considered as well formed numerical constants in lua (so it will work for '314.16e-2' too).

Function will scan editbox text and return once it finds text which cannot be interpreted as part of a number. It will return number recognized so far, or 0 if there were no valid digits recognized. The function will never return nil. For example (User input => Function returns):

  • ":)" => 0
  • "123punks! 42" => 123
  • "-2.78" => -2.7799999713898
  • "+3.15" => 0
  • "222e-03" => 0.22200000286102
  • "0.31415926536e+1" => 3.1415927410126
  • "14e6" => 14000000
  • "21,000" => 21

Note[edit]

To verify that a 0 returned is indeed the numerical value in the editbox field, convert the results of GetNumber() to a string using tostring(), and compare to the results of GetText().