473,668 Members | 2,308 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 5189
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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
I assume you are talking about this function:

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

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

if ( ctype_digit($da ta[0]) && ctype_digit($da ta[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.p hp">
$articleTable = array();

while ($row = mysql_fetch_arr ay($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($art icleTable , $articleRow );

}

foreach($articl eTable 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
3518
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
4523
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 'ShippingCost'. Use the CONVERT function to run this query. What I gather is that I'm trying to insert a varchar into a money field. That is not the case however. Both fields are money. I'm going from one SQL table on serverA to an identical...
3
6162
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 -- @NumRecords <= 0 If I uncommment CLOSE and DEALLOCATE and check the syntax I get a
6
12279
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 would like to do this by defining a NewFunc() that is different in each (code-behind) page which is called by the standard 'New' button in the toolbar. How can I get this to work? So far I have the following (which doesnt work). When the user...
4
3875
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 payments, pmt = payment) other two are not required. nper is allowed to be a number with decimals, not just an integer. Seeking sql code which will replicate the above, including nper with
4
7685
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
1794
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; ... return tempMoney;
53
8372
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 language="javascript" type="text/javascript">
2
3806
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 really confused :S this is what i have so far: print "Welcome to Money Manager" print "-----------" print
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8575
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7398
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1783
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.