473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 9863

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
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
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....
2
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...
687
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...
0
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...
18
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...
1
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"...
1
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....
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.