Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 12, 2024, 07:47:31 19:47


Login with username, password and session length


Pages: [1]
Print
Author Topic: How to convert number or float number to string  (Read 3618 times)
0 Members and 1 Guest are viewing this topic.
chai98a
Guest
« on: September 22, 2007, 02:38:08 14:38 »

We used microcode studio for create code PIC basic code
I have problem with number to show on  nokia LCD , "40.35 C "
how know with convert number to strin or string + string pls advise too Roll Eyes
Logged
freddy
Newbie
*
Offline Offline

Posts: 15

Thank You
-Given: 0
-Receive: 7


« Reply #1 on: September 22, 2007, 03:47:42 15:47 »

Number 123 to string '123' :

How many subctract 100 from 123 ? 1 time, ok '0'+1='1'=0x31(hex of ascii code)
Now i have 123-100=23
How many subctract 10 from 23 ? 2 time, ok '0'+2='2'=0x32(hex of ascii code)
Now i have 23-20=3
How many subctract 1 from 3 ? 3 time, ok '0'+3='3'=0x33(hex of ascii code)
'1'+'2'+'3'='123'

String '123' to number 123 :

unsigned char number=0;

Take the most righ digit '3'=0x33(hex of ascii code) and subctract 0x30 and you have 3
  number+=3;
Now take the digit '2'=0x32(hex of ascii code) and subctract 0x30 and you have 2
  number+=2*10;
Now take the digit '1'=0x31(hex of ascii code) and subctract 0x30 and you have 1
  number+=1*100;
3+20+100=123

 Wink
Logged
jeanninemtv
Senior Member
****
Offline Offline

Posts: 311

Thank You
-Given: 57
-Receive: 25


« Reply #2 on: September 22, 2007, 06:44:38 18:44 »

if you are using proton...
simply use DIG COMMAND

FIRST SCALE YOUR NUMBER... IF USING FLOAT USE X 10  X 100 FACTOR

THEN USE DIG COMMAND   CAPTURE EACH BOY MCDU IN EACH VAR...

THEN USE THEM IF YOU NEED TO
Logged
maiasj
Guest
« Reply #3 on: September 23, 2007, 01:10:58 01:10 »

Look at atof C function source code and translate it to basic. From f to a I use this (also in C):
void print_val(double v)  /* 0 <= V < 999.9995 */
{
     unsigned long ll;
   v*=2000; 
   ll = (long)v; 
   ll++; 
   ll>>=1; 
   st[5] = ll % 10;
   ll = ll / 10; 
   st[4] = ll % 10;
   ll = ll / 10; 
   st[3] = ll % 10;
   ll = ll / 10; 
   st[2] = ll % 10;
   ll = ll / 10; 
   st[1] = ll % 10;
   ll = ll / 10; 
   st[0] = ll % 10; 
   if (!st[0])  {
      if (!st[1])     
         st[1]=0xF0;   
      st[0]=0xF0; 
   }
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC