四捨五入をする

round関数を用いて「round(値,桁指定)」のように指定します。
桁を指定していない場合は小数点以下の四捨五入となります。

桁指定をした場合

プラスの引数での指定

「1,2,3」等プラスの引数を指定すると小数点第何位までを表示するかの指定が出来ます。
「1」を指定した場合は小数点以下1桁を残す形で、3.1415 が3.1になり
「2」を指定した場合は小数点以下2桁を残す形となり、3.14となります。

マイナスの引数での指定

上記と反対に「-1,-2,-3」とマイナスの引数で指定した場合は整数の何桁以上で四捨五入するかの指定となります。
「-1」を指定した場合は1の桁が四捨五入され1555が1560となり
「-2」を指定した場合は10の桁が四捨五入され1555が1600となります。

実際のコードと出力内容

$a = 3.1415;

echo round($a);
// >>> 3
echo round($a , 1);
// >>> 3.1
echo round($a , 2);
// >>> 3.14

$b = 1555;

echo round($b , -1);
// >>> 1560
echo round($b , -2);
// >>> 1600

切り上げをする

ceil関数を使う事で小数点以下を切り上げた数値を取得出来ます。
round関数と違い桁を指定する事は出来ないので小数点にのみ有効です。

切り下げをする

floor関数を使う事で小数点以下の切り下げた数値を取得出来ます。 ceil関数同様に、桁の指定は出来ません。

整数の切り上げ、切り捨てを行いたい場合は、ceil関数やfloor関数をそのままことが使う事ができないため、一度切り捨て(上げ)したい桁数が小数点以下になるよう調整する必要があります。

$b = 1555;
echo ceil(($b / 100) * 100);
// >>> 1600
echo floor(($b / 100) * 100);
// >>> 1500
コメントを残す
コメントを残す

  1. cialis 100mg from china

    cialis 100mg from china

  2. medco pharmacy lipitor

    medco pharmacy lipitor

  3. ventolin inhaler inhouse pharmacy

    ventolin inhaler inhouse pharmacy

  4. cialis strips より:

    cialis strips

    cialis strips

  5. sildenafil 25 mg buy online

    sildenafil 25 mg buy online

  6. buy cheapest cialis

    buy cheapest cialis

  7. discount viagra pharmacy

    discount viagra pharmacy

  8. mantra 10 tadalafil tablets

    mantra 10 tadalafil tablets

  9. rx pharmacy online

    rx pharmacy online

  10. buy generic viagra online with paypal

    buy generic viagra online with paypal

  11. buy viagra soft tabs online

    buy viagra soft tabs online

  12. how can i get viagra in canada

    how can i get viagra in canada

  13. generic viagra online uk

    generic viagra online uk

  14. discount viagra canadian pharmacy

    discount viagra canadian pharmacy

  15. sildenafil 25 mg daily

    sildenafil 25 mg daily

  16. tadalafil temperature

    tadalafil temperature

  17. free tadalafil

    free tadalafil

  18. tadalafil use in females

    tadalafil use in females

  19. when is generic cialis available

    when is generic cialis available

  20. neurontin hyperkalemia

    neurontin hyperkalemia

  21. flagyl storage

    flagyl storage

  22. trimethoprim/sulfamethoxazole ds for sinus infection

    trimethoprim/sulfamethoxazole ds for sinus infection

  23. nolvadex dischem

    nolvadex dischem

  24. lyrica narcotic controlled substance

    lyrica narcotic controlled substance

  25. valacyclovir dizziness

    valacyclovir dizziness

  26. lisinopril promethazine

    lisinopril promethazine

  27. furosemide vancomycin

    furosemide vancomycin

  28. médicament ratio-metformin

    médicament ratio-metformin

  29. empower pharmacy semaglutide reddit

    empower pharmacy semaglutide reddit

  30. semaglutide other names

    semaglutide other names

  31. semaglutide cyanocobalamin

    semaglutide cyanocobalamin

  32. how long does it take zoloft to get out of your system

    how long does it take zoloft to get out of your system

  33. flagyl intraveineuse

    flagyl intraveineuse

  34. duloxetine hcl dr 20 mg

    duloxetine hcl dr 20 mg

  35. cymbalta side effects how long do they last

    cymbalta side effects how long do they last

  36. can adderall be take with escitalopram oral

    can adderall be take with escitalopram oral

  37. cephalexin make you sleepy

    cephalexin make you sleepy

  38. sildenafil 20 mg tablet brand name

    sildenafil 20 mg tablet brand name

  39. does lexapro make you gain weight

    does lexapro make you gain weight

  40. can you take bactrim and keflex together

    can you take bactrim and keflex together

  41. fluoxetine is generic for what

    fluoxetine is generic for what

  42. gabapentin litigation

    gabapentin litigation

  43. cephalexin for fish

    cephalexin for fish

  44. ciprofloxacin and tylenol

    ciprofloxacin and tylenol

  45. does bactrim treat chlamydia

    does bactrim treat chlamydia

  46. what does bactrim look like

    what does bactrim look like

  47. アバター Carson より:

    My coder is trying to persuade me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he's tryiong none the less. I've been using Movable-type
    on a variety of websites for about a year and am concerned about switching to another platform.

    I have heard good things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?
    Any help would be greatly appreciated!

    my website: chocolate shrooms

  48. アバター Lavada より:

    Today, I went to the beach front with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her
    ear and screamed. There was a hermit crab inside and it
    pinched her ear. She never wants to go back! LoL
    I know this is entirely off topic but I had to tell
    someone!

    my site ... amanita muscaria mushroom

  49. flomax after turp surgery

    flomax after turp surgery

  50. ddavp test von willebrand

    ddavp test von willebrand

  51. is amoxicillin a penicillin

    is amoxicillin a penicillin

  52. diltiazem side effects mayo clinic

    diltiazem side effects mayo clinic

  53. depakote er dosage

    depakote er dosage

  54. does flexeril show up on drug test

    does flexeril show up on drug test

  55. contrave and zoloft reddit

    contrave and zoloft reddit

  56. how long for effexor to work

    how long for effexor to work

  57. who makes cozaar

    who makes cozaar

  58. what antihistamine can i take with citalopram

    what antihistamine can i take with citalopram

  59. efectos adversos del ezetimibe

    efectos adversos del ezetimibe

  60. augmentin es 600

    augmentin es 600

  61. diclofenac potassium side effects

    diclofenac potassium side effects

  62. nortriptyline vs amitriptyline

    nortriptyline vs amitriptyline

  63. buffered aspirin for dogs

    buffered aspirin for dogs

  64. side effects of allopurinol 300 mg

    side effects of allopurinol 300 mg

  65. aripiprazole price walmart

    aripiprazole price walmart

  66. is celebrex safe to take

    is celebrex safe to take

  67. another name for celexa

    another name for celexa

  68. bupropion medication

    bupropion medication

  69. can you snort baclofen 10 mg

    can you snort baclofen 10 mg

  70. celecoxib (celebrex)

    celecoxib (celebrex)

  71. how long does buspar last

    how long does buspar last

  72. ashwagandha during pregnancy

    ashwagandha during pregnancy

  73. abilify maintena 400 mg

    abilify maintena 400 mg

  74. seroquel and remeron

    seroquel and remeron

  75. repaglinide metformin hplc

    repaglinide metformin hplc

  76. protonix coupon

    protonix coupon

  77. is robaxin a good muscle relaxer

    is robaxin a good muscle relaxer

  78. acarbose carcinogenicity

    acarbose carcinogenicity

  79. what are the long term side effects of semaglutide

    what are the long term side effects of semaglutide

  80. actos rcp より:

    actos rcp

    actos rcp

  81. tizanidine and gabapentin

    tizanidine and gabapentin

  82. does voltaren have carbs

    does voltaren have carbs

  83. sitagliptin 100 mg price in india

    sitagliptin 100 mg price in india

  84. fluconazole synthroid

    fluconazole synthroid

  85. how to wean off venlafaxine 75 mg

    how to wean off venlafaxine 75 mg

  86. medikament tamsulosin esparma

    medikament tamsulosin esparma

  87. joint pain spironolactone

    joint pain spironolactone

  88. stromectol tablets uk

    stromectol tablets uk