473,508 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function to check money value

Hi,

I am looking for a good function to check if a entered value is
a money value - meaning it's a decimal with no more then 2 digits after the point.

Thanks,

Stefan
Jul 17 '05 #1
7 5181
I noticed that Message-ID:
<e2**************************@posting.google.com > from Stefan Richter
contained the following:

I am looking for a good function to check if a entered value is
a money value - meaning it's a decimal with no more then 2 digits after the point.


Check user notes.
http://php.net/manual/en/function.eregi.php

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
On 14 Feb 2005 05:13:03 -0800, Do****@gmx.de (Stefan Richter) wrote:
I am looking for a good function to check if a entered value is
a money value - meaning it's a decimal with no more then 2 digits after the point.


Something along the lines of:

preg_match('/^\d+(?:\.\d\d?)$/', $money_value)

Do you want to allow it to be preceded by a currency symbol? How about commas
for thousands separators, or allowing mainland-European-style separators
(points for thousand separators, comma for decimal e.g. 1.000,99)?

The above would be OK if all you want is "digits followed optionally by [dot
plus one or two digits]".

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
I assume you are talking about this function:

function check_price($price)
{
$data=split('[.]',$price);

if ( count($data) != 2 )
return "false";

if ( ctype_digit($data[0]) && ctype_digit($data[1]) && $data[0][0]
!= '0')
return "true";
else
return "false";
}

However, there are two problems:
1. I can't find this ctype_digit function in my php reference, so I
assume it doesn't exist.

2. How can I switch from german to english number format???

I thought number_format($money,2,".",",") would do it,
however, it seems that this chops of existing values after the comma /
dot.

???

Thanks,

Stefan
Jul 17 '05 #4
Hi, I want to go create a table with a textfield where the user can
enter an amount for a certain dynamically created article coming from
the database.

Later, I want to calculate the whole price and so on.
It works nicely to create my multi dimensional array,
however, it does not work to save the values coming from the form to
calculate the price.
What's wrong???

<form name="shop" method="post" action="index.php">
$articleTable = array();

while ($row = mysql_fetch_array($result)) {
$articleNr= $row["articleNr"];
$name= $row["name"];
$picName= $row["picName"];
$price = $row["price"];
$amount="";
$articleRow = array(
"articleNr" => $articleNr,
"name" => $name,
"picName" => $bildName,
"price " => $price ,
"amount" => $amount
);

array_push($articleTable , $articleRow );

}

foreach($articleTable as $article) {
?>
<input type="text" name="article[amount]" size="2" maxlength="2"
value="<? $article[amount] ?>"></td>
}

<?
}
?>
</form>
Jul 17 '05 #5
Thanks for your reply Andy.
-------

Well, first of all it needs to be able to be saved my mysql.
Can mysql understand thousands seperators?
If not, I would need a function to take out these seperators.

About . vs ,:

Well, this function is for Germany,
so I would need it the other way round,
but the best was if it would except both of course.
And no, I don't need a currency symbol, as I am always using euros so
I am not saving that in the database.
Thanks,

Stefan
Jul 17 '05 #6
I noticed that Message-ID:
<e2**************************@posting.google.com > from Stefan Richter
contained the following:
Later, I want to calculate the whole price and so on.
It works nicely to create my multi dimensional array,
however, it does not work to save the values coming from the form to
calculate the price.
What's wrong???


There is no code there which does that. And if you already have an
array called $row why change it to an array called $articleRow It seems
identical apart from the variable $bildName which appears from nowhere.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7
Geoff Berrow <bl******@ckdog.co.uk> wrote in message news:<cb********************************@4ax.com>. ..
I noticed that Message-ID:
<e2**************************@posting.google.com > from Stefan Richter
contained the following:
Later, I want to calculate the whole price and so on.
It works nicely to create my multi dimensional array,
however, it does not work to save the values coming from the form to
calculate the price.
What's wrong???


There is no code there which does that. And if you already have an
array called $row why change it to an array called $articleRow It seems
identical apart from the variable $bildName which appears from nowhere.


Sorry, I forgot to change that variable name to english - it's
picname,
and yes basically they are identically -

Okay, that was stupid -

Anyway - All I want is an array that contains the data coming from the
databse
AND also the amount of each article coming from the form the user
fills.

I was able to make an array containing the amount of each article,
and I got the array coming from the database -
Now what I just don't like is that I don't have any evidence that
row[0] of the first array is identically to row[0] to my amount array
-
If I had all in one array, I could easily go through the array and
work with it - no matter if it was sorted or not.

Stefan
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
3496
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
1
4517
by: shank | last post by:
I'm getting the following error... Microsoft OLE DB Provider for SQL Server error '80040e07' Disallowed implicit conversion from data type varchar to data type money, table 'wsOrders', column...
3
6154
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE --...
6
12261
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
4
3866
by: tdick | last post by:
Does anyone know sql of the PV function in Access? (same function in Excel) In access the inputs are PV («rate», «nper», «pmt», «fv», «due») where rate = discount rate, nper = number of...
4
7675
by: Paul | last post by:
Anyone have code that emulates the Nz function in Microsoft Access? In Access it is: Nz(Value as variant, Optional ValueIfNull as Variant) as Variant
11
1779
by: Xiaoshen Li | last post by:
Dear Sir, I am a little puzzled about a function returning a class object, for example, suppose I hava a class Money and a method: Money lastYear(Money aMoney) { Money tempMoney; ......
53
8315
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
2
3798
by: compdude | last post by:
Hello everyone, i need some help on my programming in python i am trying to make a program that can ask for information and document it on a excel spreadsheet. Im a beginner programmer and i am...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.