473,387 Members | 1,528 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,387 software developers and data experts.

Format float

Hi all,

Is it possible to adjust the number of digits in a float?

For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
want 0.33
Is there a function or do i have to use round($test*100)/100

Thanx,
WJ
May 14 '06 #1
2 23342
Rik
WJ Zeeuwen wrote:
Hi all,

Is it possible to adjust the number of digits in a float?

For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
want 0.33
Is there a function or do i have to use round($test*100)/100


I'd use round($test,2);
Also possible is number_format();

Grtz,
--
Rik Wasmus
May 14 '06 #2
WJ Zeeuwen wrote:
Hi all,

Is it possible to adjust the number of digits in a float?

For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
want 0.33
Is there a function or do i have to use round($test*100)/100

Thanx,
WJ


If all you want to do is display the value 0.33 without actually changing the
number (which will affect future math operations), you can use

printf("%01.2f", 0.33);

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 14 '06 #3

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

Similar topics

2
by: Alexander Schmidt | last post by:
Hi, I am not very familiar with C++ programming, so before I do a dirty hack I ask for a more elegant solution (but only the usage of STL is allowed, no special libs). So I need to read a file...
16
by: David | last post by:
I have following code. float b; b= 1.234; cout<<hex<<b<<endl; How come it cannot ouput the hex representation of b?
5
by: geskerrett | last post by:
We are working on a project to decipher a record structure of an old accounting system that originates from the late80's mid-90's. We have come across a number format that appears to be a "float"...
3
by: Mahmood Ahmad | last post by:
Hi, I am getting the error 'Input String was not in correct format' in the following C# program (indicated line): using System; namespace CF7 { class CalcArea {
9
by: gamehack | last post by:
Hi all, I've been wondering when I write a structure like: struct { int a; unsigned int b; float c; } mystruct;
7
by: fmt | last post by:
Hello, I have float comming from database as .5. I need it to format to look like .50. Please advice Thanks
7
by: Aek | last post by:
Hi everyone, I am trying to construct a regular expression and format string to use with a boost::regex_replace() In my file the sample text is: // .fx shader file FLOAT JOE 3545f; FLOAT...
12
by: astri | last post by:
i`m doing my thesis comparing CORDIC with polynomial in counting arctan with fixed point. I`m using Q15 format now. I`m using this site CORDIC arctan as a referenced when making with floating...
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
4
by: siddhanta | last post by:
float x = new float; float y = new float; int c=0; using (StreamReader sr = new StreamReader("e: \\CuPeak.dat")) { while (!sr.EndOfStream) {
0
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,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.