Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Converting Single to String with 2 decimals


  • Please log in to reply
7 replies to this topic

#1 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 17 October 2012 - 07:56 PM

Hello to all,
I have a litte problem and I have a workaround, but I am wondering howto solve this with Globalisation? I suppose?


Sub Main()

        Dim sngExampleA As Single = 1234.5678
        Dim sngExampleB As Single = 1234.5678


        Debug.Print(sngExampleA.ToString)
        'result 1234.56775    '

        Debug.Print(sngExampleB.ToString("N2"))
        'result 1,234.57      '

    End Sub

I want the 2 decimals but I do not want the comma in the result so 1234.57
But how program this in VB?
Thank you Ellen

#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 17 October 2012 - 08:10 PM

Try ToString("#.##")

#3 DrJaymz

DrJaymz

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 17 October 2012 - 09:06 PM

Try ToString("#.##")


ToString("F2")

??

#4 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 17 October 2012 - 09:07 PM

Try ToString("#.##")

No, I have tried:

#### Exception System.ArgumentException - 0x00000000 (1) ####
#### Message:
#### System.Number::ValidateFormat [IP: 003f] ####
#### System.Number::Format [IP: 0008] ####
#### System.Single::ToString [IP: 000d] ####
#### NetduinoPlusApplication1.Module1::Main [IP: 001c] ####
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll

#5 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 17 October 2012 - 09:09 PM

ToString("F2")

??

Yes Thats the solution, thank you Dr Jaymz.

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 October 2012 - 07:30 AM

Try ToString("#.##")

The ToString is a bit bugged still though. See also: http://netmf.codeple...m/workitem/1322
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 DrJaymz

DrJaymz

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 18 October 2012 - 09:02 PM

Yes Thats the solution, thank you Dr Jaymz.


Yay.... I am so used to using String.Format that I really miss it, but obviously handling strings on a puny system like this is always going to be slow or memory intensive. I'm glad that F2 works for you and I don't know why I can't find it documented anywhere.

#8 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 19 October 2012 - 01:06 PM

Yay.... I am so used to using String.Format that I really miss it, but obviously handling strings on a puny system like this is always going to be slow or memory intensive. I'm glad that F2 works for you and I don't know why I can't find it documented anywhere.

Yes Dr. Jaymzas, as a student (in hobby VB) I have search on the Internet, but nothing. Is it not strange, Microsoft wants so badly to promote the Micro environment but document it badly. (in my opinion)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.