whats a floating point and whats the difference between floating point and decimal point
The string format function doesn’t have a “decimal point” specifier. If you mean %d
, that specifier is for integers. Most of the specifiers can be given a precision value which in the case of a %f
float will only show the most significant digits after the “decimal point” for the number.
i still dont understand please elaborate more
All non-integers can be represented in a format that has a decimal point, but none of the specifiers use “decimal” or “d” to indicate a formatted number that uses a decimal point. The word “decimal” is used for some of the integer specifiers, which don’t actually place a decimal point in the string representation.
idk why im not getting it , do u want to say that %d doesnt exist or what?
I would never claim that. Are you having trouble formatting a number into a string? You don’t need to know all of the format specifiers for most tasks.
no i just wanna know the differnece it has been bothering me for a long time
The difference between %f
and %d
?
yeah and the differenece btw flosting and decimal point
%f
is for non-integers. 0.5
, one-third, or pi are all non-integers that are acceptable to be formatted as a float.
%d
is for integers. Every number that is divisible by 1 without a remainder. 1
, 1000000
, -77
. If you have a count of some objects that can’t be reduced to a fractional form, like how many players are in the game, then that number is acceptable to be formatted as an integer.
You’ll need to share what you mean by decimal point.
doesnt decimal mean numbers like 0.3 , -1.39 ect… if so why do we call them too floating point thats what i m not understanding and besides isnt %i for intergers?
%d
and %i
are aliases for the integer specifier. In the docs, “decimal” likely just refers to the decimal base system (10) that we’re used to. The specifier descriptions also use octal (base 8) and hexadecimal (base 16) to describe different base representations.
A floating point number is called a floating point because the radix point “.” can be anywhere in the number. This radix point is also known as a decimal separator. That’s probably where confusion can arise.
if i understand u correctly then i ve comprehended that %d is the same as %d and for whatever reason if i make a script that checks if for example 2784.43 using %d it should return nil or error or whatsever right?
well about the floating point part i ve learnd in school that (8,-2,1982…ect) are called integers and (8.2203 | -1.23 ect…) are called decimal numbers i ve never learnd about floating point or what so ever called
Roblox does not error or return nil if a float is given for an integer specifier. It silently rounds the number into an integer.
string.format("%d", 5.15) -- prints string '5'. the '.15' is lost.
Floating point numbers are relevant in computer science because that’s how a common way that computers represent numbers. It’d be a bit out of scope for a math class to teach floating point numbers.
A simple directive is the character %´ plus a letter that tells how to format the argument:
d´ for a decimal number, x´ for hexadecimal,
o´ for octal, f´ for a floating-point number,
s´ for strings
it says d for decimal and f for floating points and the given examples are confusing me since i think it would work on both f and d no? and it says d is decimal not integers
Decimal means base 10. Not numbers with a decimal point. Lua takes inspiration from printf
, the print function of the C language. Its documentation describes %d
and %i
as a:
Signed decimal integer
oh i see…
btw the given exmaple u have given me didnt work kn a lua complier instead it threw an error “bad argumet”
I specifically mean Roblox Luau. A bare Lua interpreter likely gives
that error because it doesn’t want to silently round the number. In Roblox, it is silently rounded.
alr thanks for sticking with me till the end