Jump to content


Photo

Exact Value


  • This topic is locked This topic is locked
4 replies to this topic

#1 shan_cool

shan_cool
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts
  • LocationChennai,India

Posted 27 March 2006 - 09:36 AM

Hi all

I want to add 2 fields in PHP and i don't want the output to be rounded off,I need the exact value,say for eg
Ist field value is 1.23 and
2nd field value is 2.89

I want the output to be 4.12 not 4

can anybody help me
shan

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 27 March 2006 - 09:53 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
$number1=1.23;
$number2=2.89;
echo $number1 + $number2;
?>[/quote]

That works fine for me :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 27 March 2006 - 09:54 AM

decimal/float numbers don't get rounded off unless you specify.

$a = 1.23;
$b = 2.89;

$c = $a+b;
echo $c;

// output is 4.12

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#4 shan_cool

shan_cool
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts
  • LocationChennai,India

Posted 27 March 2006 - 10:22 AM

Hi,

Thanks very much for ur reply,I am printing the value in excel so it rounding off by itself,so how can i do this..

Please help

Thnks in Advance,
shan

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 27 March 2006 - 10:33 AM

In case you hadn't noticed, this is a PHP forum, NOT M$ Office.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users