Skript

Skript

788k Downloads

Add expression that gets the number of decimal places in a number

graphicality opened this issue · 4 comments

commented

Suggestion

I think that there definitely should be an expression to get the number of decimal places in a number.
For example:

on chat:
if message is "123.456":
set {_dec} to decimal places of (message parsed as number) # example syntax, returns integer for # places
if {_dec} is greater than 2:
send "Hey! We only use two decimal places around here!" to player
else: if {_dec} is less than or equal to 2:
send "Gooood boy! Proper decimal places!" to player

Why?

While you can do this with addons I believe, I see no reason as to why it shouldn't be included in the base version of Skript.
It simplifies code from multiple lines of splitting strings and parsing them yada yada to a simple expression.
Many ways of character counting and number formatting are already in Skript, why not round out the bases? (pun intended)

Other

No response

Agreement

  • I have read the guidelines above and affirm I am following them with this suggestion.
commented

Why not check if mod(({_num} * 100), 1) != 0? it will pass if you use more than 2 decimals

commented

IIRC we use this information in the "numbers between" expression, it may be nice to expose it to users

commented

Yeah you could do that but if the whole point of skript is to make a more comprehensible text based language and its possible to simply it why not? I can’t imagine it would take a ton of work to create something like this and I think it would be beneficial

commented

Yeah you could do that but if the whole point of skript is to make a more comprehensible text based language and its possible to simply it why not? I can’t imagine it would take a ton of work to create something like this and I think it would be beneficial

The reasonable way to do it would mean something like decimal places of (2^53 + 0.12345) would be 0, not 5