Answered by:
input number with decimal point
Question

This is a sample for input numbers with decimal point in a textbox. At the End the program round the number with 2 numbers after the decimal point.
show ZKW930
If you have a better routine, please send it.
2012/11/26
Uuuh, there was a mistake by numbers with no or one numbers after the decimal point.
the corection program is ZKW9300
Best Regards Martin
Answers

litdev, that was very clever!
Although it's more of a SB's glitch, which doesn't remove excessive zeros after normal arithmetic operations.
But it does remove them when using Math's category functions!
So, just for the sake of completeness, I've also added the dottocomma display snippet:
num = 162.295
dec = 2
Decimal()
Commas()
TextWindow.WriteLine("")
Sub Decimal
tmp = Math.Power(10, dec)
num = 1/tmp * Math.Round(num * tmp)
EndSub
Sub Commas
dot = Text.GetIndexOf(num, ".")
If dot = 0 Then
TextWindow.Write(num)
Else
TextWindow.Write( Text.GetSubText(Num 1, dot1) )
TextWindow.Write( "," + Text.GetSubTextToEnd(Num, dot+1) )
EndIf
EndSub
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
 Edited by GoToLoopEditor Monday, November 26, 2012 9:17 PM
 Marked as answer by martmen Tuesday, November 27, 2012 3:33 AM
All replies


Hello Martin!
Here's a very basic decimal point formatting snippet.
Though it does not fill in zeros to right nor replaces points w/ commas. Needs more code for it! :P
num = 162.2883 dec = 2 Decimal() TextWindow.WriteLine(num) Sub Decimal tmp = Math.Power(10, dec) num = Math.Round( num * tmp ) / tmp EndSub
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
 Edited by GoToLoopEditor Monday, November 26, 2012 7:59 PM

This puts the zeros after point
num = 162.0 dec = 2 Decimal() TextWindow.WriteLine(num) Sub Decimal tmp = Math.Power(10, dec) num = 1/tmp * Math.Round( num * tmp ) EndSub
 Edited by litdevModerator Monday, November 26, 2012 8:28 PM
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Wednesday, November 28, 2012 5:51 AM

litdev, that was very clever!
Although it's more of a SB's glitch, which doesn't remove excessive zeros after normal arithmetic operations.
But it does remove them when using Math's category functions!
So, just for the sake of completeness, I've also added the dottocomma display snippet:
num = 162.295
dec = 2
Decimal()
Commas()
TextWindow.WriteLine("")
Sub Decimal
tmp = Math.Power(10, dec)
num = 1/tmp * Math.Round(num * tmp)
EndSub
Sub Commas
dot = Text.GetIndexOf(num, ".")
If dot = 0 Then
TextWindow.Write(num)
Else
TextWindow.Write( Text.GetSubText(Num 1, dot1) )
TextWindow.Write( "," + Text.GetSubTextToEnd(Num, dot+1) )
EndIf
EndSub
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
 Edited by GoToLoopEditor Monday, November 26, 2012 9:17 PM
 Marked as answer by martmen Tuesday, November 27, 2012 3:33 AM