Hi there,
I am wanting to store price data as n.nn format, so if the user enters "1"
the data that gets stored is "1.00"
Is there a way to do this.
Cheers
Steven 8 2155
.oO(Steven) I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00"
Is there a way to do this. http://www.php.net/number_format
Micha
Hi there,
Thnaks for that, I have tried using it to format the number as it is
submitted to the database, but it doesnt seem to work.
I can format a number coming out of the database easy enough, but want to
do the conversion on the way in.
Has anyone used number_format() to format the form data ie:
<input type="text" name="first_value" size="20" value="<?php echo
$first_value; ?>">
All this seems to do is format the initial value to n.nn rather than the
number entered into the form field.
cheers
Steven
"Michael Fesser" <ne*****@gmx.net> wrote in message
news:qi********************************@4ax.com... .oO(Steven)
I am wanting to store price data as n.nn format, so if the user enters
"1"the data that gets stored is "1.00"
Is there a way to do this.
http://www.php.net/number_format
Micha
You should be able to format the number prior to the database insertion
query using number_format for example:
$first_value = number_format($first_value, 2);
then insert it into the database.
Steven wrote: Hi there,
Thnaks for that, I have tried using it to format the number as it is submitted to the database, but it doesnt seem to work.
I can format a number coming out of the database easy enough, but
want to do the conversion on the way in.
Has anyone used number_format() to format the form data ie:
<input type="text" name="first_value" size="20" value="<?php echo $first_value; ?>">
All this seems to do is format the initial value to n.nn rather than
the number entered into the form field.
cheers
Steven "Michael Fesser" <ne*****@gmx.net> wrote in message news:qi********************************@4ax.com... .oO(Steven)
I am wanting to store price data as n.nn format, so if the user
enters "1"the data that gets stored is "1.00"
Is there a way to do this.
http://www.php.net/number_format
Micha ad**@adamcoppin.com wrote in message news:<10**********************@c13g2000cwb.googleg roups.com>... You should be able to format the number prior to the database insertion query using number_format for example: $first_value = number_format($first_value, 2); then insert it into the database.
Steven wrote: Hi there,
Thnaks for that, I have tried using it to format the number as it is submitted to the database, but it doesnt seem to work.
I can format a number coming out of the database easy enough, but want to do the conversion on the way in.
Has anyone used number_format() to format the form data ie:
<input type="text" name="first_value" size="20" value="<?php echo $first_value; ?>">
All this seems to do is format the initial value to n.nn rather than the number entered into the form field.
cheers
Steven "Michael Fesser" <ne*****@gmx.net> wrote in message news:qi********************************@4ax.com... .oO(Steven)
>I am wanting to store price data as n.nn format, so if the user enters "1" >the data that gets stored is "1.00" > >Is there a way to do this.
http://www.php.net/number_format
Micha
if you're using mysql, have a look at column type 'decimal'. don't
know about other db's though.
micha
Steven wrote: I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00"
Is there a way to do this.
You have to define the column as text -- not a good idea!
Defining the column as text loses you the ability to make calculations
with values in that column; you can't sum a bunch of strings;
"28.00" < "4.00"; ...
As far as the database is concerned
1 == 1.0 == 1.00 == 1.000 == 1.0000 == ...
just get the number and format it on the way out with number_format()
--
USENET would be a better place if everybody read: | to mail me: simply | http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, | http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text | http://www.expita.com/nomime.html | and *NO* attachments. |
"Pedro Graca" <he****@hotpop.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de... Steven wrote: I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00"
Is there a way to do this. You have to define the column as text -- not a good idea! Defining the column as text loses you the ability to make calculations with values in that column; you can't sum a bunch of strings; "28.00" < "4.00"; ...
Absolute rubbish! Every (competent ) database engine in the world is capable
of storing numeric fields, either as whole numbers (integers) or with
decimal places. It is a simple matter of choosing the right type. For MySQL
check out http://dev.mysql.com/doc/mysql/en/Numeric_types.html
--
Tony Marston http://www.tonymarston.net
As far as the database is concerned
1 == 1.0 == 1.00 == 1.000 == 1.0000 == ...
just get the number and format it on the way out with number_format() -- USENET would be a better place if everybody read: | to mail me: simply | http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, | http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text | http://www.expita.com/nomime.html | and *NO* attachments. |
Tony Marston wrote: "Pedro Graca" <he****@hotpop.com> wrote in message news:sl*******************@ID-203069.user.uni-berlin.de... Steven wrote: I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00"
Is there a way to do this.
You have to define the column as text -- not a good idea! Defining the column as text loses you the ability to make calculations with values in that column; you can't sum a bunch of strings; "28.00" < "4.00"; ...
Absolute rubbish! Every (competent ) database engine in the world is capable of storing numeric fields, either as whole numbers (integers) or with decimal places. It is a simple matter of choosing the right type. For MySQL check out http://dev.mysql.com/doc/mysql/en/Numeric_types.html
That's what I think: having a text column with numeric values is
absolute rubbish :-)
Hope the OP does not go that way.
mysql> create table x (n int, v int, s varchar(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert x values(1, 28, "28.00"), (2, 4, "4.00");
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from x order by v;
+------+------+-------+
| n | v | s |
+------+------+-------+
| 2 | 4 | 4.00 |
| 1 | 28 | 28.00 |
+------+------+-------+
2 rows in set (0.00 sec)
mysql> select * from x order by s;
+------+------+-------+
| n | v | s |
+------+------+-------+
| 1 | 28 | 28.00 |
| 2 | 4 | 4.00 |
+------+------+-------+
2 rows in set (0.00 sec)
mysql> drop table x;
Query OK, 0 rows affected (0.00 sec)
--
USENET would be a better place if everybody read: | to mail me: simply | http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, | http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text | http://www.expita.com/nomime.html | and *NO* attachments. |
On Thu, 28 Oct 2004 13:33:12 +1300, in comp.lang.php "Steven"
<we*******@deepweb.co.nz> wrote: | Hi there, | | I am wanting to store price data as n.nn format, so if the user enters "1" | the data that gets stored is "1.00" | | Is there a way to do this.
set the field datatype
`price` decimal(5,2) NOT NULL default '0.00',
--------------------------------------------------------------- jn****@yourpantsbigpond.net.au : Remove your pants to reply
--------------------------------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: The Roys |
last post by:
Hi
I have a textbox which displays a formatted numeric. eg: 100,000
When I retreive this value for calculations, it is valued at 100
eg:
calc = val(txtbox) * 2
calc will equal 200, not...
|
by: TP |
last post by:
Hi,
In SQL Server 2000, if I have to create a table to store a very large
number of 10 digit telephone numbers, would I be better off to have a
bigint field or just use a varchar field? If I do...
|
by: Carl G |
last post by:
I have a DataSet with a couple of tables. I have noticed that when I
am trying to store a Decimal 0.000 in a datarow, the value is changed
to 0, without the information about its decimalplaces.
...
|
by: Steven T. Hatton |
last post by:
I'm still not completely sure what's going on with C++ I/O regarding the
extractors and inserters. The following document seems a bit inconsistent:...
|
by: Trevor.Dhu |
last post by:
I am just starting to use python, and as such my question may well be a
bit simplistic. I am currently trying to write what should be a very
basic set of routines for reading and writing to a...
|
by: AndrewMBaldwin |
last post by:
So I am quite upset that after working for a few hours on getting an
XML file format and XSL file that formats the XML data appropriatly,
only to find that if you store HTML code in your XML file...
|
by: Steve |
last post by:
Hi,
I've developed a testing application that stores formatted results in a
database. Recently it was requested that I add the ability to generate
graphs from the raw, un formatted test results...
|
by: raghav |
last post by:
Hi all
I am having a SP which is returning a value......Now I have to store
that value
in session...I saw some examples in msdn lib ---->
string Name=string.Empty;
Session=Name.ToString();
...
|
by: Derek Hart |
last post by:
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName)
I want to format this and store it into a string.
I have formatting stored in a database, such as "$#,##0.00"
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |