Kain Nobel
Member
Thank you both for helping me, both methods work pretty well!
darkleo's method works for having a value between .0 and .00000000000000, just change the +m to how many decimals you want left over, but sometimes it'll cut it off to just 1 decimal digit when using thousand+ valued numbers.
kmhp's method however will always have the specified decimal ammount, as long as the last values aren't 0!
I shall now label this topic as "Resolved" :thumb:
darkleo's method works for having a value between .0 and .00000000000000, just change the +m to how many decimals you want left over, but sometimes it'll cut it off to just 1 decimal digit when using thousand+ valued numbers.
Code:
class Game_Variables
#--------------------------------------------------------------------------
# * Set Variable
# variable_id : variable ID
# value : the variable's value
#--------------------------------------------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
if value.is_a?(Float)
@value = value
@decimals = @value.to_i.size + 1
value = @value.to_s[0, 2+@decimals].to_f
end
@data[variable_id] = value
end
end
end
kmhp's method however will always have the specified decimal ammount, as long as the last values aren't 0!
Code:
class Game_Variables
#--------------------------------------------------------------------------
# * Set Variable
# variable_id : variable ID
# value : the variable's value
#--------------------------------------------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
if value.is_a?(Float)
value = sprintf('%.2f', value).to_f
end
@data[variable_id] = value
end
end
end
I shall now label this topic as "Resolved" :thumb:
How do you cut back a decimal value? For instance, when tracking Player's Screen Y, sometimes the value will show 260.35745572234523457.
How do I cut it so it only shows, like 260... or 260.3... or 260.35?
I searched the help file and tried screen_x.truncate, but it didn't do anything but error pop for me.
How do I cut it so it only shows, like 260... or 260.3... or 260.35?
I searched the help file and tried screen_x.truncate, but it didn't do anything but error pop for me.