Search code examples
javasqlitedivide-by-zero

0 divided by 0 Getting NaN(Not a Number) In Android


I want to do some calculation in my app where i divide two value lets say A and B. Some time A and B value are 0.0 and 0.0 respectively at that time i Get the output as NaN(While debugging the code) and also on Toast, But when i insert the value in sqlite db there is nothing but the blank field is inserted, why is like that can anyone explain please. NOTE: my db field is double type. thanks


Solution

  • Internally sqlite stores NaN values as NULL. It makes sense because in computational expressions, a NaN or NULL makes the whole expression NaN or NULL.

    If you want to store a NaN explictly, you can store 'NaN' as text for example.