I want to store my values as FLOATS, but when retrieving them the user can specify (and change at runtime) how many digits he wants to see after the decimal point.
Can I pass that in my SELECT somehow, or do I have to do it in my application?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, just specify the second parameter for
ROUND()With this, you can specify the number of digits you would like to get returned. (you can even have negative values, in wither case, the input gets rounded to 10(-precision)).
Or you could use
CASTasDECIMAL:(Note: this latter would work with textual inputs too, like
CAST('2.5' AS DECIMAL(20,2)), but in this case it is about FLOAT inputs)