vb.net - How to round value to nearest integer -



vb.net - How to round value to nearest integer -

i have next code, trying round value nearest integer. can't seem figure out how. have looked @ few sources none useful trying achieve. there method takes care of this? or there way can programmatically?

eg.

in database table have column sets limit single sms char length allowed ie- 160.

if input string in form < max length allowed, split input string / sms lenth allowed, , round value nearest int.

what have tried far:

if (cint(strtext.length) <= cint(maxsmslength)) doublevaluereturned = (cdec(cint(strtext.length) / cint(singlesmslength))) smscount = round(doublevaluereturned) msgbox(smscount) end if

thanks help.

the simple solution real problem (counting how many sms messages required send string of text of arbitrary size) utilize integer division (symbol \) instead of floating point division (symbol /).

the partition returns integer discarding floating point part. finding number of sms messages requires adding 1 result returned. there problem of sms message of 160 characters or multiple of 160 in case adding 1 result of integer partition yeld wrong number of messages. fixed adding 1 if remainder of partition not zero

dim smsrequired = (str.length \ maxsmslength) + (if(str.length mod maxsmslength = 0, 0, 1))

however reply asker question , not right solution in real world scenario, when want send message more 160 characters (or if message contains special characters) need split message in less 160 characters

this documented here long sms text messages , 160 character limit

vb.net windows

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -