Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Decimal Format

Decimal Format

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swiss Mantoro
    wrote on last edited by
    #1

    Hi Guys I hope some body can help me, to tell me how to format decimal value wittout round up ? Many thank for you ICE

    B 1 Reply Last reply
    0
    • S Swiss Mantoro

      Hi Guys I hope some body can help me, to tell me how to format decimal value wittout round up ? Many thank for you ICE

      B Offline
      B Offline
      Briga
      wrote on last edited by
      #2

      If you want to simply format have a look at the documentation of the formatstrings (i.e. tostring method documentation or format function).

      S 1 Reply Last reply
      0
      • B Briga

        If you want to simply format have a look at the documentation of the formatstrings (i.e. tostring method documentation or format function).

        S Offline
        S Offline
        Swiss Mantoro
        wrote on last edited by
        #3

        Mr.Briga Thank you for youra reply, actually I have ever tried to use Format string but I still got the decimal in rounding up state. The format string which was I used is "###.00" I have a example: I have three Textbox ( textbox1,textbox2,and textbox3) result from textbox1 divide to textbox2 will store in textbox3, on textbox1 I enter 12000 and on textbox2 I enter 10039, actually the result must be 1.19 store in textbox3, but when I run this program on textbox3 I see 1.20 not 1.19 as I need. Could you please to tell me how should Itype the right format on Textbox3 in order to get the right decimal format like I need. Thank you ICE

        S B 2 Replies Last reply
        0
        • S Swiss Mantoro

          Mr.Briga Thank you for youra reply, actually I have ever tried to use Format string but I still got the decimal in rounding up state. The format string which was I used is "###.00" I have a example: I have three Textbox ( textbox1,textbox2,and textbox3) result from textbox1 divide to textbox2 will store in textbox3, on textbox1 I enter 12000 and on textbox2 I enter 10039, actually the result must be 1.19 store in textbox3, but when I run this program on textbox3 I see 1.20 not 1.19 as I need. Could you please to tell me how should Itype the right format on Textbox3 in order to get the right decimal format like I need. Thank you ICE

          S Offline
          S Offline
          Steve Pullan
          wrote on last edited by
          #4

          It seems from this article: VB Format string Rounding[^] that what you are seeing is by design. I found this by googling "vb format string rounding". ...Steve

          1 Reply Last reply
          0
          • S Swiss Mantoro

            Mr.Briga Thank you for youra reply, actually I have ever tried to use Format string but I still got the decimal in rounding up state. The format string which was I used is "###.00" I have a example: I have three Textbox ( textbox1,textbox2,and textbox3) result from textbox1 divide to textbox2 will store in textbox3, on textbox1 I enter 12000 and on textbox2 I enter 10039, actually the result must be 1.19 store in textbox3, but when I run this program on textbox3 I see 1.20 not 1.19 as I need. Could you please to tell me how should Itype the right format on Textbox3 in order to get the right decimal format like I need. Thank you ICE

            B Offline
            B Offline
            Briga
            wrote on last edited by
            #5

            Than it's more about rounding/truncating rather than formatting. If you want to truncate to a certain digit you can use several approaches, two are here: 1) Function TruncateToDecX(v as double,d as double) as double v=v/d v=int(v) v=v*d return (v) end function You use it passing v=1.1999 and d=0.01 (where you want to truncate) you get 1.19 2) Quick and dirty dim s as string=v.tostring s.substring(0,s.indexof(".")+2)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups