ProtoLang.net

Reference: Float

☰ Hide Sidebar
TOKEN FLOAT
ALIAS None

The Float Data Type is used to represent numbers with decimals. Valid values (literals) are -1.175494e-38 to 3.402823e+38 (inclusive). Floats can be combined with Arithmetic operators to create Expressions. Arithmetic expressions containing Floats cannot contain Booleans, Integers or Strings.

Syntax

The short syntax structure uses the word FLOAT:

NEW FLOAT VARIABLE = VALUE

The long syntax structure uses the word FLOAT:

NEW FLOAT VARIABLE EQUAL TO VALUE

Examples

Example: Creating Integer and setting Value to Literal

NEW FLOAT x = 5.5
PRINTLN x // Displays "5.5"

Example: Creating Integer and setting Value to Variable

NEW FLOAT x = 5.5
NEW FLOAT y = x
PRINTLN y // Displays "5.5"

Example: Creating Integer and setting Value to Expression using Plus operator

NEW FLOAT x = 5.5
NEW FLOAT y = x + 5.5
PRINTLN y // Displays "11.0"

Common Errors

Error: Creating Float and setting to Boolean Literal

NEW FLOAT x = TRUE // Runtime error! Cannot assign Boolean Literal to Float Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating Float and setting to Integer Literal

NEW FLOAT x = 1 // Runtime error! Cannot assign Integer Literal to Float Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating Float and setting to String Literal

NEW FLOAT x = "1" // Runtime error! Cannot assign String Literal to Float Data Type
PRINTLN x // This line is not executed because the program crashed!