VBA - Number of decimal places in TextBox
Solved
DjSKeud
Posted messages
103
Status
Member
-
lahlah70 -
lahlah70 -
Hello everyone,
My problem is not as easy as it may seem from the title:
I want to display a value with 1 digit after the decimal point in a textBox while the actual number has 4 digits.
Note, I do not want to use round(xx, 1) on my value because I want it to retain its precision of 4 digits. In other words, is there an attribute in the TextBox object that allows displaying 1 decimal while keeping the precision at 4? (like a number format in an Excel cell)
Thank you all for your help.
--
DjSkeud,
http://tomleskeud.free.fr
My problem is not as easy as it may seem from the title:
I want to display a value with 1 digit after the decimal point in a textBox while the actual number has 4 digits.
Note, I do not want to use round(xx, 1) on my value because I want it to retain its precision of 4 digits. In other words, is there an attribute in the TextBox object that allows displaying 1 decimal while keeping the precision at 4? (like a number format in an Excel cell)
Thank you all for your help.
--
DjSkeud,
http://tomleskeud.free.fr
8 answers
-
try yourself
LeNum = 2.657856
LeNum = FormatNumber(LeNum, 1)
this is in vb -
In principle, it's the format function (in VB). But when you want to retrieve the value of this textbox, you will get the rounded value. In HTML, you can create an attribute in the <input name="MyInput" value="<MyFormattedValue" therealvalue="<MyVariable>" />. You can then search for this value with document.getElementById("MyInput").theRealValue (note that JavaScript respects case sensitivity - for functions, variables, textboxes...)!!!
-
Nothing prevents you from storing this value in a variable. VBA is just fine for that.
-
Hey,
No, I misspoke; obviously, there aren't 4000 textboxes, but actually, I have 2 dropdown lists that allow me to extract a value from a database. The thing is, for the sake of speed and ergonomics, I need to store all the modified values in a sort of temporary page, and then when all the modifications are done, I will update my database.
Thanks for your suggestion, I'll test it out quickly and keep you updated.
--
DjSkeud,
http://tomleskeud.free.fr -
... I am in VBA, unfortunately not in HTML
yes, that's really the problem, if I format, I lose the precision of my value forever!!
Thank you anyway, but the problem remains unsolved :(
--
DjSkeud,
http://tomleskeud.free.fr -
Hello,
No, I did think about it, believe me, the problem is that my TextBox is not only used for displaying values, but also for input, and on top of that, I have about 4000 values that I need to keep cached (if I use your technique) because I need access to them at all times. In other words, it is not possible to create some sort of buffer variable linking the display at 4 decimal places to the one at 1. Am I clear?
--
DjSkeud,
http://tomleskeud.free.fr -
"La TextBox serves not only as a display for values but also for input."
"I'm not following you there. You display a digit after the decimal point, right? Then we can still type in plenty of digits after the decimal point in input mode, but your display after input should show only one decimal point, while in the background you work with four decimal places. Right! What will your user say if they enter 1.4567 and then see 1.4, and in a calculation like 'times two' they see 2.9 as a result, although your display should give 2 * 1.4 = 2.8. I think there's a problem there."
"Furthermore, I have approximately 4000 values." WHAT??? In a single form, across the entire application? I also think there's a design problem with the application, but oh well."
"In summary: no, a textbox does not 'remember' an old value. But Access knows the Format property (it's not the function of the same name but a property of the textbox). This does not change the value but only its display PROVIDED THAT the field has a link to the database, i.e., the ControlSource property is used. We need to test how it behaves during input, but normally it should work for the input, but the display could mess up meaning that you see the 4 digits during input but when you do a requery the display would be correct." -