In Google Sheets, I can use the ROUND function to round to the nearest decimal.
5.1 = 5
5.5 = 6
What if I want like this:
5.1 = 6
5.5 = 6
What function should I use?
ROUNDUP is exactly what you need here.
Rounds a number to a certain number of decimal places, always rounding up to the next valid increment.
Related
I want to show positive movement in numbers. In my case moving from 4 to 3 is positive movement.
In my Google Sheets, I have 4 in cell B1 and 3 in C1. The percent change value is 1 and percent change is 33% improvement. If I use this formula =(b1-a1)/b1 I get -33%. What formula do I use to get 33% as the returned percent?
Try using ABS() function. Something like this:
ABS((b1-a1)/b1)
try like this:
=((B1-A1)/B1)*-1
Is there a formula that I could use to round a date time cell up or down (1/10/2022 15:17:02) to the nearest 15 minute interval? I've tried MROUND but since the date time field is in a weird format, I can't quite figure out how to get that to work.
Seems to work for me, example here:
https://docs.google.com/spreadsheets/d/1Hq2pep92vmPQ8kPiThNUod7nsFZopMuOAFNcLCdkJcM/edit?usp=sharing
Using =mround(A2,"00:15") to round, =floor(A2,"00:15") to round down, and =ceiling(A2,"00:15") to round up.
Perhaps you forgot to format the end result back as a Date Time itself?
See more examples here: https://infoinspired.com/google-docs/spreadsheet/round-round-up-round-down-hour-minute-second-in-google-sheets/
you can use round to round down
=round(a1*96)/96
or ceiling to round up
=ceiling(a1*96)/96
with date time fields in Sheets the date is treated like a whole number and the time like a fractional part.
so if you want to round to 15 mins - there are 24 * 4 = 96 lots of 15 minutes in one day. so multiply the date by 96, then round, then divide by 96 should do the trick.
I am using the Xcode 7 beta 5 and Swift 2. I currently have a UITextField and a UIButton. The UITextField is set to a decimal pad, but however, the user is able to enter in multiple decimals. That is not how I would like the app to work. I would like to check, when the button is tapped, if the text field has 0-1 decimal points. Is there any statement that checks for multiple decimal points?
Replace textField with a reference to your UITextField in this:
if textField.text.componentsSeperatedByString(".").count >= 3 {
// more than 1 decimal point
}
This seperates the text in the text field into an array and creates an array of strings separated on any decimal points. If there are 0-1 decimal points, the array will have less than 3 items. This documentation might be helpful.
Give the text field a delegate and implement textField:shouldChangeCharactersInRange:replacementString: to prevent the user from entering a decimal point if there is already one present.
I have a float number that could be 3.553 or 34.535 or 353.6436 I want it to be no more than 5 figures, before or after the dot, for example, for the first number I wrote it has to be 3.5530, for the second 34.535 as is and for the third 353.64.
How can I do that with NSNumberFormatter?
Use NSNumberFormatter to convert the number to a string. Specify 5 decimal digits and turn off any grouping. Once you have the string, get the index of the decimal separator. If its index is 4 or less (a number less than 10,000), take the first 6 characters of the string. If its index is 5 or more (a number greater or equal to 10,000), take the first 5 characters of the string.
You may have to adjust this depending on how you want to deal with numbers less than 1 due to the leading zero ahead of the decimal separator.
I have a picker view that displays output in a textfield. It is for the user to select an amount of time, it has hours, minutes, and seconds for the 3 rows. For this part I only am focusing on the seconds. I want to be able to convert the hours to minutes and display an output as a whole number and a decimal. I was able to convert the hours to minutes, but I am having trouble converting the seconds into a decimal. It should be as simple as dividing the row count by 60. However, I can't get that to display right. The output to the label is just 0.00 no matter what row i select.. Here is my code.
float sec;
sec = ([timePickerView selectedRowInComponent:2]/60);
Label.text = [NSString stringWithFormat:#"%.2f",sec];
The "/" sign in relation to the number "60" is considered an integer division by the compiler. Change "60" to "60.0" and you shall get the result you are expecting. You should also make sure that the [timePickerView selectedRowInComponent:2] returns a float by casting it:
(float)[timePickerView selectedRowInComponent:2]