Results 1 to 14 of 14

Thread: 2 decimal places

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Ireland
    Posts
    29
    How do i format a text box to display a number as two decimal places. Eg. number is 45.888888 and i want it displayed in the text box as 45.89

    Thanks
    Samantha
    Claire

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Text1.text = cstr(int(45.888888 *100)/100)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    The more elegant way to do stuff like this it is to use the Format() and Round() functions, they are documented in the MSDN.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Round(45.888888,2)
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I like the faster inline solution
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Originally posted by Claire
    How do i format a text box to display a number as two decimal places. Eg. number is 45.888888 and i want it displayed in the text box as 45.89

    Thanks
    Samantha
    Clair, If your username is clair, why did you sign the post with the name Samantha ?

    Just wondering
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Active
    Round(45.888888,2)
    I can remember exactly what it was, but I am pretty sure there is a bug in the rounding function?

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah i think i remember that too, btw, can you do something about your very long sig ?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Ireland
    Posts
    29
    Hi Plenderj
    My friend Samantha was here with me at the time and she posted that question!
    Claire.
    Claire

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think Round will actually round it, whereas converting to an Integer through multiplying it by 100 will truncate it instead.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    my mistake, should be

    cstr(int(45.888888 *100+0.5)/100)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by kedaman
    yeah i think i remember that too, btw, can you do something about your very long sig ?
    Sorry for the trouble

    All gone now

  13. #13
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    parksie ; love the avatar
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169


    arksie:
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width