Convert String to Number

Issues related to label design (working with databases, data processing, RFID encoding etc.) and printing (from NiceLabel Express, NiceLabel Pro, NiceForm and NicePrint)

Moderator: NiceLabel Support Team

Post Reply
Posts: 1
Joined: Fri Dec 02, 2022 9:35 am

Convert String to Number

Post by stefano_88 » Fri Dec 02, 2022 9:48 am

Hello everyone and thank you in advance if you can help.

Introduction: I am super beginner, so I hope I won't annoy anyone. Furthermore I checked the forum and the web for a solution, but I cannot have it working.

Situation: I am getting some data from a COM1 port (on the other side there is a weight scale) and putting the data into a variable. Starting from this variable, which is filled by the COM port, I use a function to extract the net weight (i.e. I extract characters from position 3 to 10 and I get a value which looks like 10.450 that I read 10kg and 450gr ).

Problem: as soon as I just look at the number everything is fine, however when I try to use this value to do some math (i.e. weight * price) the comma is not considered at all. Therefore if I use a price of 1€/Kg I get 10450€ instead of 10,45€ . I think the problem is the value being processed as a string and not as a number.

I tried to convert the value from string to number using a VBscript, but I always get an error. Do you have any piece of advice?

Thanks for your help

Posts: 4
Joined: Mon Dec 05, 2022 5:18 pm

Re: Convert String to Number

Post by linasm » Tue Dec 06, 2022 2:28 pm

In similar project used python script: Result.Value = float(Weight.Value.replace(',', '.'))

Weight variable type used floating point

Post Reply