Home Wrap fractional part of decimal in a span

# Wrap fractional part of decimal in a span

Mikhail
1#
Mikhail Published in 2018-02-13 21:22:05Z
 I am printing a variable (called something.price) to a Haml template and its value is a string representation of a decimal with 2-digit precision. I want to wrap the fractional part of the decimal (including the .) in a span. Example: If we have "1234.41", we want to wrap the span around the .41 part. How can this be achieved?
Zoran
2#
 Since you know the format of your original string (decimal, two digit precision, etc.), you can wrap the decimal point portion of that string in a  by doing something like the following: price = '1234.41' result = price.sub('.', '.').concat('') # => "1234.41"  Hope this helps!
 You can first convert to string with to_str method if it's a number, then, use the .split method, something like this: number = "1234.41"  then do something like this number.split(".") I ignore if you are doing this on backend or frontend, anyway you can find this split method on javascript. Once you have the array, you can iterate with the result.