Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Stripping decimal places


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-02-2007, 11:30 PM
Junior Member
 
Join Date: Jun 2007
Location: South Africa
Posts: 25
Awards Showcase
Beta Tester 
Total Awards: 1
Exclamation Stripping decimal places

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
Attached Files
File Type: sbp teststring.sbp (897 Bytes, 10 views)
Reply With Quote
  #2 (permalink)  
Old 11-02-2007, 11:42 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,343
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

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?
Attached Files
File Type: sbp teste.sbp (1.2 KB, 10 views)
__________________
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.
Reply With Quote
  #3 (permalink)  
Old 11-03-2007, 12:53 AM
Knows the basics
 
Join Date: Jun 2007
Location: Netherlands (Arnhem)
Posts: 71
Default

Quote:
Originally Posted by Softselect View Post
Hi All,
in my app I need to strip decimal places
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.
Reply With Quote
  #4 (permalink)  
Old 11-03-2007, 04:37 AM
Senior Member
 
Join Date: May 2007
Posts: 130
Awards Showcase
Beta Tester 
Total Awards: 1
Default Rounding or stripping

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.
Reply With Quote
  #5 (permalink)  
Old 11-03-2007, 08:07 PM
Junior Member
 
Join Date: Jun 2007
Location: South Africa
Posts: 25
Awards Showcase
Beta Tester 
Total Awards: 1
Default Solved

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
Attached Files
File Type: sbp teststring.sbp (1,014 Bytes, 6 views)
Reply With Quote
  #6 (permalink)  
Old 11-05-2007, 05:01 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 707
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default Stripping decimal places

Hello,
I suggest you a solution in the joined file.
The idea is to calculate the number of digits after the decimal point.
Then
if the number is less then 3 you add the missing zeros
else you stripp it normaly.
I hope this helps you even you found anouther solution.

Klaus
Switzerland
Attached Files
File Type: sbp teststring.sbp (1.3 KB, 7 views)
Reply With Quote
  #7 (permalink)  
Old 11-05-2007, 05:28 PM
Junior Member
 
Join Date: Jun 2007
Location: South Africa
Posts: 25
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by klaus View Post
Hello,
I suggest you a solution in the joined file.
The idea is to calculate the number of digits after the decimal point.
Then
if the number is less then 3 you add the missing zeros
else you stripp it normaly.
I hope this helps you even you found anouther solution.

Klaus
Switzerland
Thank you Klaus,
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
Reply With Quote
  #8 (permalink)  
Old 11-05-2007, 07:55 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 707
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default Stripping decimal places

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
Reply With Quote
  #9 (permalink)  
Old 11-13-2007, 10:02 PM
Junior Member
 
Join Date: Jun 2007
Location: South Africa
Posts: 25
Awards Showcase
Beta Tester 
Total Awards: 1
Wink Sample Solution

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
Attached Files
File Type: sbp Decimal stripper 1v0.sbp (1.8 KB, 9 views)
Reply With Quote
  #10 (permalink)  
Old 11-14-2007, 07:58 AM
Senior Member
 
Join Date: May 2007
Posts: 130
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 04:54 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0