Decimal Format
-
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
-
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
-
If you want to simply format have a look at the documentation of the formatstrings (i.e. tostring method documentation or format function).
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
-
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
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
-
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
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)