playMaker

Author Topic: Get a float's decimal float  (Read 1436 times)

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Get a float's decimal float
« on: September 28, 2019, 05:05:00 PM »
I want to turn 9.43 into 0.43. I want to turn 5.92 to 0.92. I tried "split float to ints", but I need a "split float to floats" to retain the decimal. or "remove whole numbers from a float."


also a "float round DOWN or UP" would solve this problem, too, as I could round it down, then save that and subtract that from the complete float number.
« Last Edit: September 28, 2019, 05:09:12 PM by westingtyler »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Get a float's decimal float
« Reply #1 on: September 29, 2019, 07:36:38 AM »
Alright, I made an action for this, using the more elegant Mathf.Repeat function. The other way you suggest is also included in a comment line. You can simply switch to this, however both give identical results, including this tiny caveat: because the trick uses rounding in either way, the outcome might be off by a very tiny fraction. In my test, 23.13742 returns 0.1374207. Or 23.13 returns 0.1299992 (i.e. off by 0.0000008).

There are complicated ways to prevent this (counting digits, then applying the rounding, using a suitable rounding strategy), but I think some rouding needs to be applied anyway if the number is used for a User Interface, and that should be an extra step.