question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guidance on storing money values in SQLite

See original GitHub issue

I am seeking some guidance for my project which will need to store money amounts in a SQLite DB from a UWP app.

From my research the .NET type of decimal is the preferred type for money. The rest of my question assumes this is correct. My model has a type

public decimal Amount { get; set; } 

and as I follow the document getting started for UWP and SQLite I create a migration. I note that in the migration it appears to tell SQLite to create a column of type decimal. My migration has the following:

Amount = table.Column<decimal>(nullable:False),

From my research SQLite has no decimal type and many people appear to prefer the use of an integer and do the old */100 to find the decimal in the integer … now I am showing my age as that is an old COBOL trick.

I would love to just store the money and issue ef statements to sum the money and I should not care where ef decides to execute those statements (in SQL or client). The Utopia 😃

I am concerned that allowing ef to handle my money storage as it may not be accurate … but then getting involved and rolling my own storage seems silly if I don’t have to.
Hence here is my question on guidance? I do not need to care as ef has me covered or I need to roll my own?

If I need to roll my own what is the consensus? Use the integer and the */100 trick within my models to expose a decimal?

Regards Chris …

Further technical details

Database Provider: SQLite: 1.1.0 Tools: 1.1.0-preview4-final Operating system: Win 10 IDE: Visual Studio 2015 patch 3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jonathanantoinecommented, Apr 17, 2019

I am really sorry @bricelam : this was an issue with my IDE which didn’t clear my cache and was still using the previous EF version.

0reactions
bricelamcommented, Apr 17, 2019

…?

Test started...
 Summary: Passed: 1, Failed: 0, Ignored: 0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Storing currency values in SQLite database
How you store your Currency in SQLite is another matter entirely. You could store it as a numeric type or even a string.,...
Read more >
Guidance on storing money values in SQLite · Issue #7232
I am seeking some guidance for my project which will need to store money amounts in a SQLite DB from a UWP app....
Read more >
sqlite - Storing currency values in SQLite3
In financial software currency is always represented as fixed-point (decimal). You can emulate it in SQLite using integers (64-bit integer holds ...
Read more >
Storing currency values: data types, caveats, best practices
The first rule here is “never use floating-point data types for storing money amounts”. Humans expect money calculations to be made in base...
Read more >
What is the best way to handle currency data and store it ...
Not sure about sqlite3, but we like to store currency data in integers as "cents" (or the other lowest currency unit) and keep...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found