Jump to content
php.lv forumi

Noapaļošana


nikidijs

Recommended Posts

Un vēl viena maza nezināšana ar rezultāta noapaļošanu.

Tātad piemērs:

 

1ls = 100sant

 

//man ir 140 sant.
$manirsantimi=140;

//cik latus varu nopirkt
$esvarunopirkt=$manirsantimi/100;

//tātad es varu iegādātes 1.4 latus
//protams vajag veselus skaitļus, tad izmantojam:
$manbuslati=number_format($esvarunopirkt, 0, '.', '');

//tagad radīs ka es varu nopirt vienu latu. 

 

Bet ja man būs 160 santīmi, tātad varēšu nopirkt 1.6 latus, jeb ja nav ciparu aiz komata, tad šis noapaļos uz augšu, tātad pa 160 santimiem nopirkšu 2 latus.

Vajadzētu tā lai visu laiku noapaļo uz leju.

 

Ceru sapratās.

Paldies.

Edited by nikidijs
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...