473,573 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting the decimal point in php

Hello php group,
I have just joined. My usual group is sitemaps and a dozen other
forums, but nobody seems to be able to come up with exactly the advice
I am after. I just know there has to be a simple answer. I have a
script that calculates everything nicely and feeds the data into my
database after first showing the result on the screen etc etc. All
works nicely except that it calculates everything to the finest decimal
place. What I don't know is how to command it to round the decimal
places to two. I've tried a number of things, taken a number of
suggestions; but I won't mention them here as they might confuse the
issue. The main thing is that I need to tell the script to operate on
an unknown number with the function of rounding to two places. Let's
say the result is $totalname; can anybody suggest how to command that
$totalname has only 2 decimal places?
Thanks for listening.
Gayle

Oct 21 '05 #1
4 9866

gayle wrote:
Hello php group,
I have just joined. My usual group is sitemaps and a dozen other
forums, but nobody seems to be able to come up with exactly the advice
I am after. I just know there has to be a simple answer. I have a
script that calculates everything nicely and feeds the data into my
database after first showing the result on the screen etc etc. All
works nicely except that it calculates everything to the finest decimal
place. What I don't know is how to command it to round the decimal
places to two. I've tried a number of things, taken a number of
suggestions; but I won't mention them here as they might confuse the
issue. The main thing is that I need to tell the script to operate on
an unknown number with the function of rounding to two places. Let's
say the result is $totalname; can anybody suggest how to command that
$totalname has only 2 decimal places?
Thanks for listening.
Gayle


straight from the manual:

echo round(1.95583, 2); // 1.96

micha

Oct 21 '05 #2
Thanks Micha,
I saw that, but it does not quite fit the script. It seems to require
already knowing the number. I also tried echo round (',',2); but no
good. I guess people would need to see the script for it to make any
sense. Too many unique variables.
Gayle

Oct 21 '05 #3
gayle wrote:
Thanks Micha,
I saw that, but it does not quite fit the script. It seems to require
already knowing the number. I also tried echo round (',',2); but no
good. I guess people would need to see the script for it to make any
sense. Too many unique variables.


Your call to round doesn't make sense, you can't round a string to two
decimal places.

Do you mean you want to format a number with , at the thousand point and
two decimal places?

If so do:

echo number_format(" 1203.120321", 2);

Cheers,
Andy
Oct 21 '05 #4
$num=1.9654321;
..
..
..
echo round($num,2);

Ian

Oct 21 '05 #5

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

Similar topics

21
4510
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/modifying the code. Thank you. .. Facundo
17
6123
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to...
2
3735
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among test methods; consequently, some results are reported to 2 decimal places, some to 3, etc. The Results subform consists of Test Parameter, Result,...
687
23097
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is...
0
1001
by: Stan Sainte-Rose | last post by:
Hi, I would like to know how to configure IIS or an asp.net page to get the decimal symbol with a . (point) instead of a , (comma). I ve changed my local setting, but I still get 3,428571 from 12 / 3.5 Stan
18
12154
by: Kuljit | last post by:
I am doing Engineering(B.Tech) in Computer Science. I have a question for which i am struggling to write a C code(program). It struck me when we were being taught about a program which counts the number of digits in a given number. I request to help me out in solving the below said question. Ask the user to enter a decimal/float...
1
6464
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located...
1
2719
by: Joza | last post by:
Hi everybody! I have question about setting decimal symbols... In some countries, for example in my country we use comma for decimal symbol, but in in some other countries it is decimal point. The problem is when I use comma and want to save data in database. For example if i want to save number 4,50 it saves like 450, but if i write 4.50...
13
10477
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am interested in what is going on behind the scenes and if there is some aspect of decimals that keep them from being used in this calculation. Thanks!...
0
7779
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...
0
7693
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...
0
8021
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. ...
0
8064
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...
0
6418
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...
1
5590
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...
0
3732
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2208
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 we have to send another system
1
1301
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.