Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Best data type for currency - asp.net & sql?

Best data type for currency - asp.net & sql?

Scheduled Pinned Locked Moved ASP.NET
questionhelpcsharpasp-netdatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FionaDM
    wrote on last edited by
    #1

    What is the best way to define money such that sql server and asp.net agree? I have defined money in my sql tables as 'money' and values are stored with 4 places after the decimal point. In asp.net I'm using CompareValidator with DataTypeCheck of type 'currency'. This is raising a problem for me because asp.net permits only two places after the decimal point and throws up a validation error for money values i.e. because they have 4 places after the decimal point. I would like to define money as having 2 places after the decimal point. How can I achieve this? Thanks Majella

    P 1 Reply Last reply
    0
    • F FionaDM

      What is the best way to define money such that sql server and asp.net agree? I have defined money in my sql tables as 'money' and values are stored with 4 places after the decimal point. In asp.net I'm using CompareValidator with DataTypeCheck of type 'currency'. This is raising a problem for me because asp.net permits only two places after the decimal point and throws up a validation error for money values i.e. because they have 4 places after the decimal point. I would like to define money as having 2 places after the decimal point. How can I achieve this? Thanks Majella

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      Use a regex validator instead and validate for ^([0-9](\.{0,1})([0-9]{0,4}))$ If you are storing 4 dp in the database, then your users may want to see all four at some point, so you might want to use a decimal datatype in .net and have some sort of formatting function for the front end.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups