• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

converting integer field into money

I'm converting a data file that has a fee field with no decimals. I need to cast this field as money but I'm stuck on how to proceed with this.

Ex:

data field = 25557
want to to convert it to show 255.57
0
jorbroni
Asked:
jorbroni
  • 3
  • 2
1 Solution
 
BrandonGalderisiCommented:
select cast(datafield as numeric(10,2)/100
from YourTable
0
 
BrandonGalderisiCommented:
or perhaps this, depending upon your db engine:


select convert(numeric(10,2), yourDataField)/100
from YourTable
0
 
jorbroniAuthor Commented:

I get the following error

Arithmetic overflow error converting varchar to data type numeric.
0
 
BrandonGalderisiCommented:
Well 10,2 was just a starting point.  If you have greater than 8 digits to the left (>99 million) then you need to expand your data type beyond 10,2.
0
 
jorbroniAuthor Commented:

Nevermind,

I figured out what I did wrong with your script.

Thanks for your help sir.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now