![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi All,
in my app I need to strip decimal places from a string after calculatio I need to strip to 3 places, but if the calculation only returns 2 then I get an error Can some one please help, its late and I have brain freeze, cant seem to figure it out Attached sample file Thanks Friedrich |
|
||||
|
I think you are not aproaching the problem the best way...
You are triming the string to find the decimal point and then fixing its length... I would go with the StrSplit aproach, as it takes a string of any length and split it into any number of strings with a comom separator.. In this case, using "," as the separator we would get alway 2 strings(eg; 12,067 would result in a strig containing "12" and another containing "067") Then by checking the length of the second (decimal) string you could perform whatever task associated... Try this: PS. although I think the code is correct, i cannot trim more than 2 number from the end of the string, can't figure why?
__________________
Paulo Gomes Porto, Portugal PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD PPC: Qtek9000, 1GB SD DLL Version Listing Last edited by Cableguy : 11-03-2007 at 12:10 AM. |
|
|||
|
Perhaps the Format command will help?
Format("+123456","F3") -> 123456.000 Format("+1.23456", "F3") -> 1.234 Scub
__________________
PPC: IPAQ 2210, 2GB, CF GPS, CF Wireless Last edited by Scubaticus : 11-03-2007 at 12:55 AM. |
|
|||
|
Hi,
For just stripping decimal places you may also apply this solution: [@scubaticus: I've learned new one, thanks] r="1E"&num1.Value newnumber=Int(textbox1.Text*r)/r For rounding decimal places: r="1E"&num1.Value newnumber=Int(textbox1.Text*r+.5)/r 'here you can manipulate the '.5' for rounding up or down. or simply use.. newnumber=Round(textbox1.Text,num1.Value) Regards,
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard Last edited by Rioven : 11-03-2007 at 04:49 AM. |
|
|||
|
Hi everyone,
I have solved my problem of restricting decimal places to 3 it is probebly not the best way but it works if you have less than 2 decimal places. (and i used a goto, big sin i know) The reason i need to do it is, that I need to store it to a file for later printing of report via PC and this needs to be done via WIFI and automaticaly on the PC i will use a utility that sits and look at a directory and print s any file that appears in it. of corse this all still needs to be done!!! just thought i might share it with yous Danke Friedrich |
|
|||
|
Quote:
That is what i was trying, but i am not actualy a programmer, so i tend to do tings the long way round. ![]() I will use it like u sugest. Danke Friedrich ![]() |
|
||||
|
Hello Friedrich
Do you want only to strip your data or do you want to round them before, in that case you can first round your numbers with the function New = Round(Old,3) and after that add the missing zeros if necessary as in the example I sent you. Klaus Switzerland |
|
|||
|
Hi Everyone,
Just in case someone is interested, I have written a new routing to trim decimal places, add missing zeros and add a decimal point if none is passed. The routine is called with a variable for the number of decimal places. Rounding is NOT needed in my case as I am working with measurements in microns. Rounding to 1 micron makes very little difference, because the basic accuracy of the instrument is 3 microns of a mm. using the round() command also trims the string but does not add missing Zeros. However this can be used in my routine by un-remarking it. I have included some remarks for clarity Thanks to all for the input to make this work. Greetings from Friedrich, in Sunny South Africa |
|
|||
|
Hi Softselect,
Nice string manipulations exercise! Can also use StrIndexOf(org,".",0) to return value of point location. ![]() Regards,
__________________
Rioven Sony Ericsson XPERIA X1i WM6.1 480x800 Display Resolution with QWERTY keyboard |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binary, Octal, Decimal, Hex converter app | agraham | Share Your Creations | 2 | 02-20-2008 05:07 PM |
| B4PPC and decimal comma | Scubaticus | Questions & Help Needed | 12 | 07-03-2007 04:21 PM |