2
if(inputUsuario >= 16.15 && inputUsuario < 16.20){
inputUsuario = 16.20;
}
if(inputUsuario >= 16.00 && inputUsuario < 16.15){
inputUsuario = 16.15;
}
if(inputUsuario >= 15.55 && inputUsuario < 16.00){
inputUsuario= 16.00;
}
if(inputUsuario >= 15.50 && inputUsuario < 15.55){
inputUsuario = 15.55;
}
if(inputUsuario >= 15.45 && inputUsuario < 15.50){
inputUsuario = 15.50;
}
This code above is an adaptation I made of something I’m developing. In this case, if the user enters a value between 15.45 and 15.50, I have to transform his input into 15.50.
Example: The user typed 16.16, so I have to turn that value into 16.20.
The big problem is that the user can enter a value between 07.00 and 23.30 and for each of these values I need to add an if to make this modification. Is there any way I can replace these ifs
?
I use the final value of input to search a spreadsheet, for this reason I need to modify the value this way. The big problem is that there is no pattern.
If there was a pattern, there would be some way to decrease these ifs? For example, if the inputs were 0.30 on 0.30.
From what I understand, looks like have a certain pattern: at each interval of
0.05
, rounded upwards to 2 decimal places of accuracy, or so (except in the case of16.00
and16.15
, round to16.15
). Anyway, just with these examples, this is what you can "guess"...– hkotsubo
@hkotsubo, thanks for the help =D. But it is quite bizarre, sometimes the numbers appear from 0.30 on 0.30, sometimes and 0.05 on 0.05, so there is a very well defined pattern.
– Gabriel Luiz
That would happen to be hours?
– Woss
Guidance for those who want to publish a reply: the result of the operation must be the own input value if this is not contained within the adjustment range.
– Augusto Vasques