You wouldn’t get “10,5” is you wrote the
Length to file by first converting it to
Float#to_s will always use period for decimal separator.
Then, when you read the file, you have the unit “10.5” as a string, which you convert to a
Float, which also will always work because
String.to_f always expect period as decimal separator.
Most often people serialize by converting the float to string. It’s simplest. Though you could serialize by using
unpack but the code becomes harder to read, I’d only do that if I had some good reason to serialize to binary format.