Welcome Guest, Not a member yet? Register   Sign In
use string helper with currency
#11

[eluser]jedd[/eluser]
[quote author="Michael Nielsen" date="1235785694"]
Also this site is only for New Zealand residence. My goal was to be able to enter a numeric value in the form then before it's entered into the database by the controller have it add $ sign so I don't have to waste time on every entry by manually typing the $ sign.
[/quote]

Okay .. the thing is you don't want a non-numeric character (the '$') in your database column where you're storing the dollar amount. There are several reasons for this. First it breaks normalisation rules for schema design (well, it does). Then there's the problem of you not being able to force one of numeric (as darkhorse suggested using float or double) column types, which would give you another layer of data type validation at the time you insert into the DB. (If you have $ you are going to have to use a text type in the database.) Then there's the benefit of being able to do in-database math on the values in those records (with the $ present, you can't). Then there's the convenience of doing out-of-DB (but in your PHP code) math on the raw fields, without having to strip each $ from each figure as you go.

There's probably more .. Smile

I'm not sure what you mean by 'so I don't have to waste time on every entry by manually typing the $ sign'. On the form you would not require the dollar character to be entered at all. If this confuses your staff, get better staff Wink - or just put a $ sign before the text box to remind them it's a dollar field.
#12

[eluser]Michael Nielsen[/eluser]
You know I think I've really confused myself over this. I can just add the $ to the string when I extract it from the database.

Simply. Why I got so caught up in it I'll never know.

Thanks everyone.
#13

[eluser]TheFuzzy0ne[/eluser]
My thoughts exactly. Hehe! It's often very easy to get hung up on the smaller details, when all you really need to do is just take a step back and see the bigger picture.
#14

[eluser]darkhouse[/eluser]
I'm very glad you came to your senses and decided to do it properly. The $ sign is just a display element, you want to keep your numbers as numbers in your database. This goes for everything, not just currency. Use the right datatypes and good things will happen.




Theme © iAndrew 2016 - Forum software by © MyBB