I want a function that can take a number (say 1000.43) and return the tens, hundreds, thousands, and decimal part. So in 1000.43, it would maybe return an array with [1000, 0, 0, .43]. I know it sounds hard but how would I do that. Maybe you can give me some advice on how to do that or can supply me with the code. Either way is greatly appreciated.
I want a function that can take a number (say 1000.43) and return the
Share
Start with a string to get a consistent picture of your number without further worrying about floating point, which is more complicated than it sounds:
(If you are starting or can start with a decimal string of the right form, you should skip this
toDecimalstep and just use the string directly.)After that, the value of each digit of the integer part can be determined by its position relative to the decimal point (i.e. the end of the integer part).