C Programming Tutorial - 36 - Rounding Numbers

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

if you want it to round as we normally do, then do Floor(number+0.5), and that will round it up if it is .5 or above, or down if it's .4 or below. You can also do Ciel(number-0.5) but who likes subtraction?
For example: you have 3.5 this would round to 4 right? Well, let's plug it in. Floor(3.5+0.5) = Floor(4.0) = 4.0.
And for 3.1? Floor(3.1+0.5) = Floor(3.6) = 3.0

SangoProductions
Автор

just use "% . 1f" this will round up the number to 1 decimal point and it will do it the way we used to do it in classes. THIS IS SIMPLE AND BEST

tayyabmazhar
Автор

i remember this easier the way as:
floor is down
ceiling is up

bharath
Автор

-1 for saying that the computer isn't as smart as smart. as stated by Sebastian, it can round to the nearest whole number. Even if round wasn't available, you could use floor(float + 0.5) for positive values.

nathnolt
Автор

Literally the first minute.
Thank you, screw ints vs floats lol

Just_som_Ottur
Автор

Idk how you make coding interesting/funny but you do

arico
Автор

Hahahah you have a good sense of humor ! xD

sayatrainheartnet
Автор

Its been 10 years. Even the jovks turned into dad joke

whyshouldihaveaname
Автор

This guy is soooo smart I'm learning advanced pro-gramming C and I'm only 11.

ifrahnoor
Автор

what is the point of using these functions if you have to specify it to where to round off to. It'd be much easier to write down the results ourselves.

sabyabhoi
Автор

protip: you can use round(x) to round to the nearest integer like normal.

tylerfusco
Автор

literally best coding youtuber, shame he disappeared

HamedAdefuwa
Автор

Geez Bucky! Go to bed! You have work in the morning!

clickclaxer
Автор

I left a like just for the quality joke

hlokomani
Автор

the sound is so low that every time my computer gives me a notification, i get scared...

justinthenerd
Автор

I had my original value as a double and printed it as "0.lf" which makes it appear as an int.
Then created a function that takes the double and adds 0.5. Hope this helps

eurus
Автор

how about i want to rounding up to nearest 0.5?
for example:
13.14 => 13.50
13.61 => 14.00
13.50 => 13.50

leonardyhoward
Автор

link or video how to round decimal numbers?

harikiranvusirikala
Автор

floor= u know what it is
ceil= plaster of a roof

irtezaasad
Автор

is he sayin smell u later at the end ? :D

hazalnut