There is a simpler way to do this than string manipulation:
- Remove the non-numeric part of the number, preserving the decimal point.
- Use Decimal.Parse[^] (or Decimal.TryParse[^]) to convert your string into a decimal
- Use Decimal.Truncate[^] to get the integer part, the result of this is a decimal, so you will need cast to int if needed. You could also use Math.Floor[^] if you want
- Subtract the integer part from the original value & perform a
ToString()
. Stripping the leading "0." from this will give you the fractional part as a string
Note storing the fractional part as an int might cause problems:
7.01 --> int = 7, fratctional string = "01" if you parse 01 to an int, you'll get 1 so your array would be 7,1
7.1 --> int = 7, fratctional string = "1" if you parse 1 to an int, you'll get 1 so your array would be 7,1 also
[Edit]
Actualy I've been an idiot: once you have the "decimal" string, you can do a string
.split('.') on it and parse the two elements in the resulting two-element array of string :doh: