Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:01:16+00:00 2026-05-27T12:01:16+00:00

I have a float = 1.30452F For my WPF UI, I need to split

  • 0

I have a float = 1.30452F

For my WPF UI, I need to split the float into three parts :

  • Part 1 : 1.30
  • Part 2 : 45
  • Part 3 : 2

A working solution is :

float myFloat = 1.30452F;

string part1 = myFloat.ToString("0.00");
string part2 = myFloat.ToString().Substring(4,2);
string part3 = myFloat.ToString().Substring(6);

Does anyone has a more performant and elegant way of splitting a float ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:01:17+00:00Added an answer on May 27, 2026 at 12:01 pm

    A slight improvement (though using the same method) would reduce your string operations. I ran your original code 1 million times and did a timer on it and it was ~890ms. This change drops that down to 328ms. A decent improvement.

    string myString = myFloat.ToString();
    string part1 = myString.Substring(0, 4);
    string part2 = myString.Substring(4, 2);
    string part3 = myString.Substring(6);
    

    I assume though that you want more than just the first 4 characters for part1. Here’s a math version. This one runs in 31ms instead.

    float part1 = (int)(myFloat * 100F) / 100F;
    int part2 = (int)((myFloat - part1) * 10000F);
    int part3 = (int)((myFloat - part1 - (part2 / 10000F)) * 100000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a float value that needs to be put into a std::string .
When I have three divs that all have float left I want the sections
I have a float variable and would like to get only the part after
I have float numbers like 3.2 and 1.6 . I need to separate the
I have a float: 1.2333333 How do I change it into a two decimal
SQL2008. I have float values in a table which need to be overriden folowing
I have a float value that i need to do some calculations on and
I have 7 float values shorted in NSMutableArray, i need to find the shortest
I have a (float) rating value as a percentage from 0..100 (where 50 =
If you have a float in MSSQLServer, to what do you map this in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.