Jump to content

Currency format in db but not on page?


mckenzie

Recommended Posts

Hello Everyone, Quick question but i'm getting data from a db and putting it onto a ASP page. The db data is in the form of currency but the data put on the page goes back to the form of normal number. Someone told me about ASCII codes or summin to solve this problem but i don't really know how to go about implementing this. Any Ideas? Anyone! Anyone! :)

Link to comment
Share on other sites

Hello Everyone, Quick question but i'm getting data from a db and putting it onto a ASP page. The db data is in the form of currency but the data put on the page goes back to the form of normal number. Someone told me about ASCII codes or summin to solve this problem but i don't really know how to go about implementing this. Any Ideas? Anyone! Anyone! :)

Its a datatyping issue. VBScript has a tendency to cast variables in the most convenient type with the narrowest bytes, and an integer datatype is about half the bytes as a currency datatype.If you store your database value in another variable, explicitly convert it to a string or a double:
Dim myPricemyPrice = cdbl(RS("Price"))'alternately:'myPrice = cstr(RS("Price"))

Link to comment
Share on other sites

Ya like :) Yahweh said, it's a data type problem that is not in string form but another, and while displaying it on page, vbscript plays the unnecessary role, if you convert that data type to sting, it will display correctly.Better if you cast your variable into string while opening a recordset. <%Dim objCon, objRs , strSqlSet objCon = Server.CreateObject("ADODB.Connection")Set objRs = Server.CreateObject("ADODB.Recordset")strSql = "SELECT CAST(myCurrencyField AS VARCHAR(20)) AS myCurrencyField FROM myTable"objCon.Open "Provider=SQLOLEDB.1..........your connection"objRs.Open strSql, objCon' this will display your currency field accuratelyResponse.Write "<b><u>Currency</u></b>" & "<br><br>"Do Whie Not objRs.Eof Response.Write objRs("myCurrencyField") Response.Write "<br>" objRs.MoveNextLoop%> Try out this also :)

Link to comment
Share on other sites

My suggestion is that you are in the wrong approach of programming. Database structure, should not have repeated values, why are you storing numbers as currencies in your data base??Do you store $5.00 in the first row, and $15.00 in the second row,....??If yes, then its the wrong database approach that you have.Hope it help you

Where id you get this idea??? Where does he say he has multiple prices in the same record??? And even if he does they could be for different purposes. There could be diffrent prices for diffrent situations.
Link to comment
Share on other sites

Hi aspnetguy.By the way, I think you do not have any notion of database at all... :)

No I don't...I am only a DBA...what would I know! :) my boss also owns some retail stores so he has me write software for those stores sometimes and there are multiple prices for each product. Depending on who the customer is they get a different price so the database record has to have the different price fields for each type of customer.Unless you are psycic then you nothing about me...maybe you should know who you are talking to before you make statements like that.
Link to comment
Share on other sites

You might be DBA or posess many great certification. But this mean nothing to me. From my point of view the way you answer, seems an arogant guy who knows too much.This is not the case my boy. You have to mess with the best before YOU CAN MAKE THE STATEMENT, LIKE YOU DEVELOP MULTIUSER SYSTEMS AN SO ON...Its pathetic reply from your side. :)

Link to comment
Share on other sites

Wow...I am sorry for what ever I did that made you think it was necessary to start making personal attacks.Since I know nothing about database design could you provide us with the right way to do things when setting up a database for this situation.

Link to comment
Share on other sites

Dhanajee,Consider this a verbal warning. If you are not capable of speaking rationally and respectfully to fellow members, especially moderators, then we will have to consider offering an official warning, post previews, temporary ban, or even expulsion from the forum. Naturally, I hope it goes no farther than this - so watch your tongue, be respectful and please try to help people. Straying off topic to make an unsupported accusation about another individual does no one any good and onlymake you look like an immature and unrespectable member that will only be ignored rather than appreciated.Now, to make a couple points on topic . . .

Link to comment
Share on other sites

There are many ways to handle databasing prices. One technique, already offered, is to store pricing information at the product level in with the actual product. Although that may work for many (maybe even most) situations, there are conditions that can make that method inappropriate.For instance, I have a client that has four or five classifications of buyers - and it has/will change. Rather than adding new price fields and adjusting code to accommodate those additional fields, it is common to create a new table for just prices. This, then requires a cross (or look up) table to match the product with the buyer catagory type. That is to say one price is entered and then related to the one category. Then the product is linked to the primary key of the price table. A product may have multiple prices simply by look adding them to the cross table. When a buyer logs in for a purchase, their customer record identifies their buyer category and then can determine the correct price.So, pricing can be done a number of ways, there is rarely a wrong way to do it - but there are scalable way to do it - and that is the important fact to understand before writing off one idea or method as being useless.For mckenzie, I would highly suggest you store prices in the database as an integer. It sounds like you might be using MS Access - if so, another suggestion would be to find away out of that (mysql and ms sql express are free). Leave the dollar formatting up to the programming language.All though I personally see very little beneift at this day in age, there are many who feel all of that formating should be done and will be done in the database - so you will have to figure out how far into the future you want to worry about this problem. If you eve have to convert the date, you may run into an application that cannot recognize the dollar format (not to mention foreign currencies here) - then you will have a biggest task to write scripts that select and remove the characters when all along you can be assured that integer to integer conversion can almost never fail.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...