Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Problem z liczbami ujemnymi i dodatnimi, no i stoimy w miejscu... :?
ApC
post 28.07.2008, 10:38:54
Post #1





Grupa: Zarejestrowani
Postów: 121
Pomógł: 0
Dołączył: 22.09.2007

Ostrzeżenie: (20%)
X----


witam was,
mam problemik ;p. otoz tak:


  1. <?php
  2. $liczba=-500;
  3. $int=(int)$liczba;
  4. $intval=intval($liczba);
  5. echo "$int, $intval";
  6. ?>


I zawsze ten minus wchodzi, bo to niby liczba calkowita. Jak poradzic sobie z tym? niektorzy wpisuja mi na stronce w formularzach -500, *500 itp, a wtedy tylko jest "dym".

dzieki za pomoc,
pzdr smile.gif

Ten post edytował ApC 28.07.2008, 10:39:08
Go to the top of the page
+Quote Post
JoShiMa
post 28.07.2008, 10:42:19
Post #2





Grupa: Zarejestrowani
Postów: 1 374
Pomógł: 149
Dołączył: 1.03.2006

Ostrzeżenie: (0%)
-----


a co chcesz uzyskać, zeby była dodatnia?

  1. <?php
  2. if($liczba <0) $liczba = $liczba*-1;
  3. ?>


--------------------
Go to the top of the page
+Quote Post
nowotny
post 28.07.2008, 10:42:42
Post #3





Grupa: Zarejestrowani
Postów: 875
Pomógł: 122
Dołączył: 2.02.2008

Ostrzeżenie: (0%)
-----


No to sprawdzaj i wywalaj error... niech poprawnie wpisują... :/
Go to the top of the page
+Quote Post
ApC
post 28.07.2008, 10:46:45
Post #4





Grupa: Zarejestrowani
Postów: 121
Pomógł: 0
Dołączył: 22.09.2007

Ostrzeżenie: (20%)
X----


No tak, musi być dodatnia. A nie ma czegoś takiego jak (int) lub intval() by funkcją to poszło snitch.gif? Tylko by siedziały mi dodatnie.
Go to the top of the page
+Quote Post
Cysiaczek
post 28.07.2008, 10:49:37
Post #5





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Może http://pl.php.net/manual/pl/function.abs.php ?


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
ApC
post 28.07.2008, 11:03:11
Post #6





Grupa: Zarejestrowani
Postów: 121
Pomógł: 0
Dołączył: 22.09.2007

Ostrzeżenie: (20%)
X----


Dzięki bardzo. pomogło. użyłem:
  1. <?php
  2. $liczba=-500;
  3. $liczba=abs($liczba);
  4. $liczba=intval($liczba);
  5. echo "$liczba";
  6. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 02:39