I am having the strangest issue, to me at least, related to Number Data Type.
-
Is it normal that if I import csv file that has numbers with precious of more than two I lose that on the import? I have records that have up to 10 precision but they only imported up to 2 decimals. When I update the record though in the collection it allows me to have more than 2 decimals precision.
-
I have a field on a page that has a data type of Number. The Collection it goes to has the data type as Number. However after inserting or updating a record in that collection, when I go to the collection that record has the small orange box that says I need to convert the value. This applies to numbers with or without decimals. Not I am not doing any data type or format conversion in the code. Am I missing something? Or can I ignore this?
ad 1) are you looking at it in Content Manager (you know, the grid). CM uses browser locale to display its data. So good chance the decimals are still there, just not shown. Try reading them from the db in a page a see what they really hold.
ad 2) known anomaly: although you can set the TextInput-element (I stress the word “Text”) to “Number”, it ALWAYS, as documented, returns a string (yes, I know, it’s … strange). SO when you try to write that to db into a number field, you get the “type mismatch” in CM. Solution: before writing to db, convert string to number using .parseFloat.
And when you read it from db and want to put it in the TextInput element, convert it to a string using .toString(), to prevent the console warning that you try to put a number into a string.
@giri-zano thanks for that. I kinda thought something of that nature was occuring bit needed confirmation. Thanks.
One additional question. Would it make sense then to just change the collection data types to all ‘Text’ and just convert back and forth necessary for calculations and display?
@leinhto Not really, when converting to text, you loose all kind of settings (locales), like decimal separator, thousands seperator etc.